diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9e9f15f..9611a63 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -8,6 +8,7 @@ MainWindow::MainWindow(QWidget *parent) kdk::UkuiStyleHelper *lf = kdk::UkuiStyleHelper::self(); lf->removeHeader(this); this->setMouseTracking(true); + this->setFocus(); m_bridge = Bridge::getInstance(); FileProcess(); diff --git a/src/module/cursorthemefeature.cpp b/src/module/cursorthemefeature.cpp index 91a21f1..be2ede0 100644 --- a/src/module/cursorthemefeature.cpp +++ b/src/module/cursorthemefeature.cpp @@ -64,11 +64,35 @@ void CursorImageWidget::updateImage(const QString& imagePath) int row = 1; int col = 0; + // 创建有序的键值对列表 + QList> sortedList; for (auto it = m_iconMap->begin(); it != m_iconMap->end(); ++it) { - // 添加新的图像项到场景中 - const QString& widgetName = it.key(); - const QString& filePath = it.value(); + sortedList.append(qMakePair(it.key(), it.value())); + } + std::sort(sortedList.begin(), sortedList.end(), [this](const QPair& pair1, const QPair& pair2) { + QStringList order1 = QStringList() << "left_ptr" << "dnd-none" << "hand1" << "hand2" << "right_ptr" + << "dnd-ask"<< "dnd-copy" << "dnd-link" + << "h_double_arrow" << "v_double_arrow" << "ul_angle" << "ur_angle" + << "left_tee" << "bottom_tee"<< "top_tee" << "right_tee" << "cross" << "tcross" + << "sb_up_arrow" << "sb_left_arrow" << "sb_down_arrow" << "sb_right_arrow" << "all-scroll" + << "sb_h_double_arrow" << "sb_v_double_arrow" << "vertical_text" << "xterm" + << "zoom-in" << "zoom-out" + << "circle" << "color-picker" << "pencil" << "dotbox" << "X_cursor" << "plus"; + QStringList order2 = QStringList() << "left_ptr_watch_1" << "left_ptr_watch_2" << "left_ptr_watch_3" << "left_ptr_watch_4" << "left_ptr_watch_5" + << "watch_1" << "watch_2" << "watch_3" << "watch_4" << "watch_5" << "watch_6" << "watch_7" << "watch_8" << "watch_9" << "watch_10"; + + if (m_iconMap->contains("left_ptr_watch_1")) { + return order2.indexOf(pair1.first) < order2.indexOf(pair2.first); + } else { + return order1.indexOf(pair1.first) < order1.indexOf(pair2.first); + } + }); + + for (const auto& pair : sortedList) { + // 添加新的图像项到场景中 + const QString& widgetName = pair.first; + const QString& filePath = pair.second; QPixmap pixmap(filePath); if (!pixmap.isNull()) { QGraphicsPixmapItem* item = graphicsView->scene()->addPixmap(pixmap.scaled(128, 128)); @@ -137,10 +161,10 @@ void CursorImageWidget::updateIconMap(const QMap *newIconMap) // 创建有序的键值对列表 QList> sortedList; - for (auto it = newIconMap->begin(); it != newIconMap->end(); ++it) { + for (auto it = m_iconMap->begin(); it != m_iconMap->end(); ++it) { sortedList.append(qMakePair(it.key(), it.value())); } - std::sort(sortedList.begin(), sortedList.end(), [this, newIconMap](const QPair& pair1, const QPair& pair2) { + std::sort(sortedList.begin(), sortedList.end(), [this](const QPair& pair1, const QPair& pair2) { QStringList order1 = QStringList() << "left_ptr" << "dnd-none" << "hand1" << "hand2" << "right_ptr" << "dnd-ask"<< "dnd-copy" << "dnd-link" << "h_double_arrow" << "v_double_arrow" << "ul_angle" << "ur_angle" @@ -153,7 +177,7 @@ void CursorImageWidget::updateIconMap(const QMap *newIconMap) QStringList order2 = QStringList() << "left_ptr_watch_1" << "left_ptr_watch_2" << "left_ptr_watch_3" << "left_ptr_watch_4" << "left_ptr_watch_5" << "watch_1" << "watch_2" << "watch_3" << "watch_4" << "watch_5" << "watch_6" << "watch_7" << "watch_8" << "watch_9" << "watch_10"; - if (newIconMap->contains("left_ptr_watch_1")) { + if (m_iconMap->contains("left_ptr_watch_1")) { return order2.indexOf(pair1.first) < order2.indexOf(pair2.first); } else { return order1.indexOf(pair1.first) < order1.indexOf(pair2.first); @@ -174,7 +198,6 @@ void CursorImageWidget::updateIconMap(const QMap *newIconMap) QPixmap pixmap(filePath); if (!pixmap.isNull()) { QGraphicsPixmapItem* item = scene->addPixmap(pixmap.scaled(128, 128)); - item->setPos(col * 128, row * 128); item->setScale(1.0); item->setData(0, widgetName); diff --git a/src/module/savepathdialog.cpp b/src/module/savepathdialog.cpp index f31dd41..8bf4309 100644 --- a/src/module/savepathdialog.cpp +++ b/src/module/savepathdialog.cpp @@ -5,6 +5,7 @@ SavePathDialog::SavePathDialog(QWidget *parent) : kdk::KDialog(parent) { this->setFixedSize(QSize(424,186)); + this->setFocus(); QWidget*mainwindow = mainWidget(); QGridLayout *layout = new QGridLayout(mainwindow); diff --git a/src/titlebar.cpp b/src/titlebar.cpp index 63c326a..d6db6ce 100644 --- a/src/titlebar.cpp +++ b/src/titlebar.cpp @@ -57,8 +57,12 @@ TitleBar::TitleBar(QWidget *parent) : QWidget(parent) connect(m_gohomebtn, &QPushButton::clicked, this,[=](){ emit gohomesignal(); + this->parentWidget()->setFocus(); + }); + connect(m_minimumbtn, &QPushButton::clicked, this, [=](){ + this->parentWidget()->parentWidget()->showMinimized(); + this->parentWidget()->setFocus(); }); - connect(m_minimumbtn, &QPushButton::clicked, parent, &QWidget::showMinimized); connect(m_maximumbtn, &QPushButton::clicked, this, &TitleBar::toggleMaximize); connect(m_closebtn, &QPushButton::clicked, parent, &QWidget::close); @@ -141,7 +145,9 @@ void TitleBar::toggleMaximize() m_ismaximized = false; // 设置最大化按钮的图标为最大化图标 m_maximumbtn->setIcon(QIcon::fromTheme("window-maximize-symbolic")); + m_maximumbtn->setToolTip(tr("Minimize")); } + this->parentWidget()->setFocus(); } void TitleBar::setGoHomeBtn(bool isable) @@ -151,7 +157,7 @@ void TitleBar::setGoHomeBtn(bool isable) }else{ m_gohomebtn->setDisabled(true); } - + this->parentWidget()->setFocus(); } void TitleBar::mouseDoubleClickEvent(QMouseEvent *event) @@ -162,3 +168,22 @@ void TitleBar::mouseDoubleClickEvent(QMouseEvent *event) QWidget::mouseDoubleClickEvent(event); } + +void TitleBar::mouseMoveEvent(QMouseEvent *event) +{ + bool isMaximized = isMaximizedDuringDrag(); + + if (isMaximized) { + m_ismaximized = true; + } else { + m_ismaximized = false; + m_maximumbtn->setIcon(QIcon::fromTheme("window-maximize-symbolic")); + m_maximumbtn->setToolTip(tr("Minimize")); + } + QWidget::mouseMoveEvent(event); +} + +bool TitleBar::isMaximizedDuringDrag() const { + // 检查窗口状态是否包含最大化标志 + return (windowState() & Qt::WindowMaximized) != 0; +} diff --git a/src/titlebar.h b/src/titlebar.h index 9b4b70d..0da285c 100644 --- a/src/titlebar.h +++ b/src/titlebar.h @@ -28,6 +28,8 @@ signals: void savePathUpdate(const QString& filePath); protected: void mouseDoubleClickEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + private: bool m_ismaximized; QToolButton *m_optionbtn = nullptr; // 菜单选项 @@ -37,6 +39,7 @@ private: QPushButton *m_closebtn = nullptr; SavePathDialog *m_savepathdlg; + bool isMaximizedDuringDrag() const; }; #endif // TITLEBAR_H