| 274 | } |
| 275 | |
| 276 | void ActiveWindowControlWidget::updateMenu() { |
| 277 | qDebug() << "ActiveWindowControlWidget#updateMenu() starts, current winID reported by menuModel is " << this->m_appMenuModel->winId() |
| 278 | << ", current winID reported by panel is " << this->currActiveWinId; |
| 279 | foreach (auto *label, this->buttonLabelListBak) { |
| 280 | label->deleteLater(); |
| 281 | } |
| 282 | this->buttonLabelListBak.clear(); |
| 283 | |
| 284 | QList<QString> existedMenu; // tricks for twice menu of libreoffice |
| 285 | for (int r = 0; r < m_appMenuModel->rowCount(); ++r) { |
| 286 | QString menuStr = m_appMenuModel->data(m_appMenuModel->index(r, 0), AppMenuModel::MenuRole).toString(); |
| 287 | |
| 288 | // tricks to remove useless old menus |
| 289 | existedMenu.append(menuStr); |
| 290 | |
| 291 | // create new clickable label for the new menu item |
| 292 | auto *m_label = new QClickableLabel(this->m_menuWidget); |
| 293 | menuStr = menuStr.remove('&'); |
| 294 | int index = menuStr.lastIndexOf('('); |
| 295 | if (index > 0) { |
| 296 | menuStr = menuStr.mid(0, index); |
| 297 | } |
| 298 | m_label->setText(QString(" %1 ").arg(menuStr)); |
| 299 | m_label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); |
| 300 | connect(m_label, &QClickableLabel::clicked, this, &ActiveWindowControlWidget::menuLabelClicked); |
| 301 | this->buttonLabelListBak.append(m_label); |
| 302 | } |
| 303 | |
| 304 | qDebug() << "organizeMenu() triggered by menuUpdate event"; |
| 305 | this->organizeMenu(); |
| 306 | qDebug() << "ActiveWindowControlWidget#updateMenu() ends"; |
| 307 | } |
| 308 | |
| 309 | void ActiveWindowControlWidget::menuLabelClicked() { |
| 310 | auto *label = dynamic_cast<QClickableLabel*>(sender()); |