!88 fix some error

Merge pull request !88 from likehomedream/kylin-theme-builder-dev
This commit is contained in:
KevinDuan 2023-12-27 06:04:47 +00:00 committed by Gitee
commit f5870f11f2
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 62 additions and 9 deletions

View File

@ -8,6 +8,7 @@ MainWindow::MainWindow(QWidget *parent)
kdk::UkuiStyleHelper *lf = kdk::UkuiStyleHelper::self(); kdk::UkuiStyleHelper *lf = kdk::UkuiStyleHelper::self();
lf->removeHeader(this); lf->removeHeader(this);
this->setMouseTracking(true); this->setMouseTracking(true);
this->setFocus();
m_bridge = Bridge::getInstance(); m_bridge = Bridge::getInstance();
FileProcess(); FileProcess();

View File

@ -64,11 +64,35 @@ void CursorImageWidget::updateImage(const QString& imagePath)
int row = 1; int row = 1;
int col = 0; int col = 0;
// 创建有序的键值对列表
QList<QPair<QString, QString>> sortedList;
for (auto it = m_iconMap->begin(); it != m_iconMap->end(); ++it) { for (auto it = m_iconMap->begin(); it != m_iconMap->end(); ++it) {
// 添加新的图像项到场景中 sortedList.append(qMakePair(it.key(), it.value()));
const QString& widgetName = it.key(); }
const QString& filePath = it.value(); std::sort(sortedList.begin(), sortedList.end(), [this](const QPair<QString, QString>& pair1, const QPair<QString, QString>& 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); QPixmap pixmap(filePath);
if (!pixmap.isNull()) { if (!pixmap.isNull()) {
QGraphicsPixmapItem* item = graphicsView->scene()->addPixmap(pixmap.scaled(128, 128)); QGraphicsPixmapItem* item = graphicsView->scene()->addPixmap(pixmap.scaled(128, 128));
@ -137,10 +161,10 @@ void CursorImageWidget::updateIconMap(const QMap<QString, QString> *newIconMap)
// 创建有序的键值对列表 // 创建有序的键值对列表
QList<QPair<QString, QString>> sortedList; QList<QPair<QString, QString>> 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())); sortedList.append(qMakePair(it.key(), it.value()));
} }
std::sort(sortedList.begin(), sortedList.end(), [this, newIconMap](const QPair<QString, QString>& pair1, const QPair<QString, QString>& pair2) { std::sort(sortedList.begin(), sortedList.end(), [this](const QPair<QString, QString>& pair1, const QPair<QString, QString>& pair2) {
QStringList order1 = QStringList() << "left_ptr" << "dnd-none" << "hand1" << "hand2" << "right_ptr" QStringList order1 = QStringList() << "left_ptr" << "dnd-none" << "hand1" << "hand2" << "right_ptr"
<< "dnd-ask"<< "dnd-copy" << "dnd-link" << "dnd-ask"<< "dnd-copy" << "dnd-link"
<< "h_double_arrow" << "v_double_arrow" << "ul_angle" << "ur_angle" << "h_double_arrow" << "v_double_arrow" << "ul_angle" << "ur_angle"
@ -153,7 +177,7 @@ void CursorImageWidget::updateIconMap(const QMap<QString, QString> *newIconMap)
QStringList order2 = QStringList() << "left_ptr_watch_1" << "left_ptr_watch_2" << "left_ptr_watch_3" << "left_ptr_watch_4" << "left_ptr_watch_5" 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"; << "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); return order2.indexOf(pair1.first) < order2.indexOf(pair2.first);
} else { } else {
return order1.indexOf(pair1.first) < order1.indexOf(pair2.first); return order1.indexOf(pair1.first) < order1.indexOf(pair2.first);
@ -174,7 +198,6 @@ void CursorImageWidget::updateIconMap(const QMap<QString, QString> *newIconMap)
QPixmap pixmap(filePath); QPixmap pixmap(filePath);
if (!pixmap.isNull()) { if (!pixmap.isNull()) {
QGraphicsPixmapItem* item = scene->addPixmap(pixmap.scaled(128, 128)); QGraphicsPixmapItem* item = scene->addPixmap(pixmap.scaled(128, 128));
item->setPos(col * 128, row * 128); item->setPos(col * 128, row * 128);
item->setScale(1.0); item->setScale(1.0);
item->setData(0, widgetName); item->setData(0, widgetName);

View File

@ -5,6 +5,7 @@ SavePathDialog::SavePathDialog(QWidget *parent) :
kdk::KDialog(parent) kdk::KDialog(parent)
{ {
this->setFixedSize(QSize(424,186)); this->setFixedSize(QSize(424,186));
this->setFocus();
QWidget*mainwindow = mainWidget(); QWidget*mainwindow = mainWidget();
QGridLayout *layout = new QGridLayout(mainwindow); QGridLayout *layout = new QGridLayout(mainwindow);

View File

@ -57,8 +57,12 @@ TitleBar::TitleBar(QWidget *parent) : QWidget(parent)
connect(m_gohomebtn, &QPushButton::clicked, this,[=](){ connect(m_gohomebtn, &QPushButton::clicked, this,[=](){
emit gohomesignal(); 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_maximumbtn, &QPushButton::clicked, this, &TitleBar::toggleMaximize);
connect(m_closebtn, &QPushButton::clicked, parent, &QWidget::close); connect(m_closebtn, &QPushButton::clicked, parent, &QWidget::close);
@ -141,7 +145,9 @@ void TitleBar::toggleMaximize()
m_ismaximized = false; m_ismaximized = false;
// 设置最大化按钮的图标为最大化图标 // 设置最大化按钮的图标为最大化图标
m_maximumbtn->setIcon(QIcon::fromTheme("window-maximize-symbolic")); m_maximumbtn->setIcon(QIcon::fromTheme("window-maximize-symbolic"));
m_maximumbtn->setToolTip(tr("Minimize"));
} }
this->parentWidget()->setFocus();
} }
void TitleBar::setGoHomeBtn(bool isable) void TitleBar::setGoHomeBtn(bool isable)
@ -151,7 +157,7 @@ void TitleBar::setGoHomeBtn(bool isable)
}else{ }else{
m_gohomebtn->setDisabled(true); m_gohomebtn->setDisabled(true);
} }
this->parentWidget()->setFocus();
} }
void TitleBar::mouseDoubleClickEvent(QMouseEvent *event) void TitleBar::mouseDoubleClickEvent(QMouseEvent *event)
@ -162,3 +168,22 @@ void TitleBar::mouseDoubleClickEvent(QMouseEvent *event)
QWidget::mouseDoubleClickEvent(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;
}

View File

@ -28,6 +28,8 @@ signals:
void savePathUpdate(const QString& filePath); void savePathUpdate(const QString& filePath);
protected: protected:
void mouseDoubleClickEvent(QMouseEvent *event); void mouseDoubleClickEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
private: private:
bool m_ismaximized; bool m_ismaximized;
QToolButton *m_optionbtn = nullptr; // 菜单选项 QToolButton *m_optionbtn = nullptr; // 菜单选项
@ -37,6 +39,7 @@ private:
QPushButton *m_closebtn = nullptr; QPushButton *m_closebtn = nullptr;
SavePathDialog *m_savepathdlg; SavePathDialog *m_savepathdlg;
bool isMaximizedDuringDrag() const;
}; };
#endif // TITLEBAR_H #endif // TITLEBAR_H