From f9bfc7b89125dfa0e1aad83d550c6562db18458e Mon Sep 17 00:00:00 2001 From: xibowen Date: Fri, 24 Mar 2023 16:47:15 +0800 Subject: [PATCH] New upstream version 4.0.0.0 --- .../platform-theme-fontdata.cpp | 184 ++++++++ .../platform-theme-fontdata.h | 61 +++ .../qt5-ukui-platform-theme.cpp | 130 +++--- .../qt5-ukui-platform-theme.h | 3 + .../qt5-ukui-platformtheme.pro | 8 +- .../widget/filedialog/debug.h | 4 - .../widget/filedialog/kyfiledialog.cpp | 426 +++++++++++++----- .../widget/filedialog/kyfiledialog.h | 14 +- .../widget/filedialog/kyfiledialogprivate.cpp | 2 - .../widget/filedialog/kyfiledialogprivate.h | 2 - .../widget/filedialog/menutoolbutoon.cpp | 3 - .../widget/filedialog/menutoolbutoon.h | 2 - .../widget/filedialog/pathbar.cpp | 2 - .../widget/filedialog/pathbar.h | 2 - .../widget/filedialog/sidebar.cpp | 5 +- .../widget/filedialog/sidebar.h | 3 - .../widget/filedialog/ui_kyfiledialog.cpp | 26 +- .../widget/filedialog/ui_kyfiledialog.h | 3 - .../widget/messagebox/message-box.cpp | 115 +++-- ukui-qml-style-helper/KyIcon.cpp | 11 +- ukui-qml-style-helper/KyIcon.h | 6 +- ukui-qml-style-helper/kyquickstyleitem.cpp | 12 +- ukui-qml-style-helper/kyquickstyleitem.h | 9 + ukui-qml-style-helper/kystylehelper.cpp | 2 +- .../org.ukui.style/RoundButton.qml | 43 ++ .../proxy-style/proxy-style-plugin.cpp | 5 +- .../kabstract-style-parameters.cpp | 88 ++-- .../kabstract-style-parameters.h | 4 +- ukui-styles/qt5-style-ukui/qt5-ukui-style.cpp | 108 +++-- ukui-styles/qt5-style-ukui/view-helper.cpp | 15 +- 30 files changed, 970 insertions(+), 328 deletions(-) create mode 100644 qt5-ukui-platformtheme/platform-theme-fontdata.cpp create mode 100644 qt5-ukui-platformtheme/platform-theme-fontdata.h create mode 100644 ukui-qqc2-style/org.ukui.style/RoundButton.qml diff --git a/qt5-ukui-platformtheme/platform-theme-fontdata.cpp b/qt5-ukui-platformtheme/platform-theme-fontdata.cpp new file mode 100644 index 0000000..1835f37 --- /dev/null +++ b/qt5-ukui-platformtheme/platform-theme-fontdata.cpp @@ -0,0 +1,184 @@ +/* + * Qt5-UKUI's Library + * + * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this library. If not, see . + * + * Authors: Yue Lan + * + */ +#include "platform-theme-fontdata.h" +#include + +#undef signals +#undef slots +#undef emit + +#include + +PlatformThemeFontData::PlatformThemeFontData() +{ + +} + +PlatformThemeFontData::~PlatformThemeFontData() +{ + +} + +bool PlatformThemeFontData::chooseFontFile(QString path) +{ + QStringList list = path.split("."); + QString fontTypeTTF = "ttf"; + QString fontTypeOTF = "otf"; + QString fontType = list.at(list.size()-1); + + if (fontType.compare(fontTypeTTF, Qt::CaseInsensitive) == 0) { + return true; + } else if (fontType.compare(fontTypeOTF, Qt::CaseInsensitive) == 0) { + return true; + } + + return false; +} + +QMap PlatformThemeFontData::getAllFontInformation() +{ + QMap fontMap; + QList ret; + ret.clear(); + + FT_Library ft_library; + FT_Error err = FT_Init_FreeType(&ft_library); + + if (err != FT_Err_Ok) { + qCritical() << "Error : LibFun , getAllFontInformation , init freetype fail"; + + return fontMap; + } + + if (!FcInitReinitialize()) { + qCritical() << "Error : LibFun , getAllFontInformation , init font list fail"; + + return fontMap; + } + + FcConfig *config = FcInitLoadConfigAndFonts(); + FcPattern *pat = FcPatternCreate(); + FcObjectSet *os = FcObjectSetBuild(FC_FILE , FC_FAMILY , FC_STYLE , FC_INDEX , NULL); + + FcFontSet *fs = FcFontList(config , pat , os); + + qInfo() << "Info : LibFun , getAllFontInformation , total matching fonts is " << fs->nfont; + + for (int i = 0 ; i < fs->nfont && fs != NULL ; i++) { + FontInformation item; + FcChar8 *path = NULL; + FcChar8 *family = NULL; +// FcChar8 *style = NULL; + int index; + + FcPattern *font = fs->fonts[i]; + + if (FcPatternGetString(font , FC_FILE , 0 , &path) == FcResultMatch && + FcPatternGetString(font , FC_FAMILY , 0 , &family) == FcResultMatch && +// FcPatternGetString(font , FC_STYLE , 0 , &style) == FcResultMatch && + FcPatternGetInteger(font , FC_INDEX , 0 , &index) == FcResultMatch) + { + item.path = QString((char *)path); + item.family = QString((char *)family); +// item.style = QString((char *)style); + } + + /* 对字体文件进行判断(判断后缀名是否为.ttf .otf)*/ + if (!chooseFontFile(item.path)) { + continue; + } + + gchar *fontData = NULL; + gsize fontDataLenth; + g_autoptr(GError) error = NULL; + + GFile *fd = g_file_new_for_path((const gchar *)path); + if (!g_file_load_contents(fd , NULL , &fontData , &fontDataLenth , NULL , &error)) { + qWarning() << "Waring : LibFun , getAllFontInformation , load font file fail , Path is [ " << path << " ]" << " error is [ " << error->message << " ]"; + + ret << item; + + continue; + } + + FT_Error ft_error; + FT_Face ft_retval; + + ft_error = FT_New_Memory_Face(ft_library , (const FT_Byte *)fontData , (FT_Long)fontDataLenth , index , &ft_retval); + if (ft_error != FT_Err_Ok) { + qWarning() << "Waring : LibFun , getAllFontInformation , read font data fail , Path is [ " << path << " ]"; + + ret << item; + + continue; + } + + /* + ///名字 + if (ft_retval->family_name) { + item.name = QString((char *)ft_retval->family_name); + } + + ///样式 + if (ft_retval->style_name) { + item.style = QString((char *)ft_retval->style_name); + } + + ///路径 + g_autofree gchar *location = NULL; + location = g_file_get_path(fd); + item.path = QString((char *)location); + + ///种类 + g_autoptr(GFileInfo) fileInfo; + fileInfo = g_file_query_info(fd , G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," G_FILE_ATTRIBUTE_STANDARD_SIZE , G_FILE_QUERY_INFO_NONE , NULL , NULL); + if (fileInfo != NULL) { + g_autofree gchar *fileType = g_content_type_get_description(g_file_info_get_content_type(fileInfo)); + + item.type = QString((char *)fileType); + } + + qDebug() << "name:" << item.name << "style:" << item.style << "path:" << item.path << "family:" << item.family; + */ + + ret << item; + fontMap.insert(item.family, item.path); + + FT_Done_Face(ft_retval); + g_object_unref(fd); + g_free(fontData); + } + + if (pat) { + FcPatternDestroy(pat); + } + + if (os) { + FcObjectSetDestroy(os); + } + + if (fs) { + FcFontSetDestroy(fs); + } + return fontMap; +} + diff --git a/qt5-ukui-platformtheme/platform-theme-fontdata.h b/qt5-ukui-platformtheme/platform-theme-fontdata.h new file mode 100644 index 0000000..96abf38 --- /dev/null +++ b/qt5-ukui-platformtheme/platform-theme-fontdata.h @@ -0,0 +1,61 @@ +/* + * Qt5-UKUI's Library + * + * Copyright (C) 2020, Tianjin KYLIN Information Technology Co., Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this library. If not, see . + * + * Authors: Yue Lan + * + */ + +#ifndef PLATFORMTHEMEFONTDATA_H +#define PLATFORMTHEMEFONTDATA_H + +#include +#include +#include +#include +#include + + +typedef struct _FontInformation +{ + QString path; /* 路径 */ + QString family; /* 系列 */ + QString style; /* 样式 */ + // QString name; /* 名称 */ + // QString type; /* 种类 */ + // QString version; /* 版本 */ + // QString copyright; /* 版权 */ + // QString manufacturer; /* 商标 */ + // QString description; /* 描述 */ + // QString designer; /* 设计师 */ + // QString license; /* 许可证 */ +} FontInformation; + +class PlatformThemeFontData : public QObject +{ + Q_OBJECT +public: + PlatformThemeFontData(); + ~PlatformThemeFontData(); + + public: + QMap getAllFontInformation(); + bool chooseFontFile(QString path); + +}; + +#endif // PLATFORMTHEMEFONTDATA_H diff --git a/qt5-ukui-platformtheme/qt5-ukui-platform-theme.cpp b/qt5-ukui-platformtheme/qt5-ukui-platform-theme.cpp index 41ea02f..942b184 100644 --- a/qt5-ukui-platformtheme/qt5-ukui-platform-theme.cpp +++ b/qt5-ukui-platformtheme/qt5-ukui-platform-theme.cpp @@ -50,6 +50,7 @@ #include "widget/messagebox/message-box.h" #include "widget/filedialog/kyfiledialog.h" #include "widget/filedialog/debug.h" +#include "platform-theme-fontdata.h" #if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON) static bool isDBusTrayAvailable() { @@ -65,6 +66,69 @@ static bool isDBusTrayAvailable() { } #endif +void Qt5UKUIPlatformTheme::slotChangeStyle(const QString& key) +{ + auto settings = UKUIStyleSettings::globalInstance(); + if (key == "iconThemeName" || key == "icon-theme-name") { + QString icontheme = settings->get("icon-theme-name").toString(); + + QIcon::setThemeName(icontheme); + + QIcon icon = qApp->windowIcon(); + qApp->setWindowIcon(QIcon::fromTheme(icon.name())); + // update all widgets for repaint new themed icons. + for (auto widget : QApplication::allWidgets()) { + widget->update(); + } + } + + if (key == "systemFont" || key == "system-font") { + //Skip QGuiApplication avoid it crash when we setfont + auto *app = qobject_cast(qApp); + if(app == nullptr) + return; + + QString font = settings->get("system-font").toString(); + + QFontDatabase db; + int id = 0; + if (!db.families().contains(font)) { + PlatformThemeFontData fontData; + QMap fontMap = fontData.getAllFontInformation(); + if(fontMap.contains(font)){ + auto iter = fontMap.find(font); + id = QFontDatabase::addApplicationFont(iter.value()); + } + } + + QFontDatabase newDb; + if (newDb.families().contains(font)) { + QFont oldFont = QApplication::font(); + m_system_font.setFamily(font); + m_fixed_font.setFamily(font); + oldFont.setFamily(font); + QApplication::setFont(oldFont); + } + } + if (key == "systemFontSize" || key == "system-font-size") { + //Skip QGuiApplication avoid it crash when we setfont + auto *app = qobject_cast(qApp); + if(app == nullptr) + return; + + if (qApp->property("noChangeSystemFontSize").isValid() && qApp->property("noChangeSystemFontSize").toBool()) + return; + double fontSize = settings->get("system-font-size").toString().toDouble(); + if (fontSize > 0) { + QFont oldFont = QApplication::font(); + m_system_font.setPointSize(fontSize); + m_fixed_font.setPointSize(fontSize*1.2); + oldFont.setPointSizeF(fontSize); + QApplication::setFont(oldFont); + } + } +} + Qt5UKUIPlatformTheme::Qt5UKUIPlatformTheme(const QStringList &args) { //FIXME: @@ -95,55 +159,16 @@ Qt5UKUIPlatformTheme::Qt5UKUIPlatformTheme(const QStringList &args) QApplication::setFont(m_system_font); } - connect(settings, &QGSettings::changed, this, [=](const QString &key){ - if (key == "iconThemeName") { - QString icontheme = settings->get("icon-theme-name").toString(); + if (app->applicationName().toLower().contains(QLatin1String("kwin"))) { + QDBusConnection::sessionBus().connect(QString(), + QStringLiteral("/UKUIPlatformTheme"), + QStringLiteral("org.ukui.UKUIPlatformTheme"), + QStringLiteral("refreshFonts"), + this, + SLOT(slotChangeStyle(QString))); + } - QIcon::setThemeName(icontheme); - - QIcon icon = qApp->windowIcon(); - qApp->setWindowIcon(QIcon::fromTheme(icon.name())); - // update all widgets for repaint new themed icons. - for (auto widget : QApplication::allWidgets()) { - widget->update(); - } - } - - if (key == "systemFont") { - //Skip QGuiApplication avoid it crash when we setfont - auto *app = qobject_cast(qApp); - if(app == nullptr) - return; - - QString font = settings->get("system-font").toString(); - QFontDatabase db; - if (db.families().contains(font)) { - QFont oldFont = QApplication::font(); - m_system_font.setFamily(font); - m_fixed_font.setFamily(font); - oldFont.setFamily(font); - QApplication::setFont(oldFont); - } - } - if (key == "systemFontSize") { - //Skip QGuiApplication avoid it crash when we setfont - auto *app = qobject_cast(qApp); - if(app == nullptr) - return; - - if (qApp->property("noChangeSystemFontSize").isValid() && qApp->property("noChangeSystemFontSize").toBool()) - return; - double fontSize = settings->get("system-font-size").toString().toDouble(); - if (fontSize > 0) { - QFont oldFont = QApplication::font(); - m_system_font.setPointSize(fontSize); - m_fixed_font.setPointSize(fontSize*1.2); - oldFont.setPointSizeF(fontSize); - QApplication::setFont(oldFont); - } - } - - }); + connect(settings, &QGSettings::changed, this, &Qt5UKUIPlatformTheme::slotChangeStyle); } // // add qqc2 style @@ -239,11 +264,7 @@ bool Qt5UKUIPlatformTheme::usePlatformNativeDialog(DialogType type) const { switch (type) { case QPlatformTheme::FileDialog: -#ifdef UseNativeFileDialog return true; -#else - return false; -#endif case QPlatformTheme::FontDialog: case QPlatformTheme::ColorDialog: return false; @@ -262,11 +283,7 @@ QPlatformDialogHelper *Qt5UKUIPlatformTheme::createPlatformDialogHelper(DialogTy { switch (type) { case QPlatformTheme::FileDialog: -#ifdef UseNativeFileDialog return new KyFileDialogHelper; -#else - return QPlatformTheme::createPlatformDialogHelper(type); -#endif case QPlatformTheme::FontDialog: case QPlatformTheme::ColorDialog: return QPlatformTheme::createPlatformDialogHelper(type); @@ -302,4 +319,5 @@ QPlatformSystemTrayIcon *Qt5UKUIPlatformTheme::createPlatformSystemTrayIcon() co return new QDBusTrayIcon(); return nullptr; } + #endif diff --git a/qt5-ukui-platformtheme/qt5-ukui-platform-theme.h b/qt5-ukui-platformtheme/qt5-ukui-platform-theme.h index 8fb8152..9c1f389 100644 --- a/qt5-ukui-platformtheme/qt5-ukui-platform-theme.h +++ b/qt5-ukui-platformtheme/qt5-ukui-platform-theme.h @@ -86,6 +86,9 @@ public: QPlatformSystemTrayIcon *createPlatformSystemTrayIcon() const override; #endif +public Q_SLOTS: + void slotChangeStyle(const QString& key); + private: QFont m_system_font; QFont m_fixed_font; diff --git a/qt5-ukui-platformtheme/qt5-ukui-platformtheme.pro b/qt5-ukui-platformtheme/qt5-ukui-platformtheme.pro index 7c6e5ed..41465be 100644 --- a/qt5-ukui-platformtheme/qt5-ukui-platformtheme.pro +++ b/qt5-ukui-platformtheme/qt5-ukui-platformtheme.pro @@ -15,8 +15,8 @@ TARGET = qt5-ukui-platformtheme TEMPLATE = lib CONFIG += plugin CONFIG += c++11 link_pkgconfig lrelease -PKGCONFIG += gsettings-qt Qt5XdgIconLoader peony kysdk-waylandhelper -LIBS += -lX11 +PKGCONFIG += gsettings-qt Qt5XdgIconLoader peony fontconfig freetype2 +LIBS += -lX11 -lfontconfig -lfreetype include(../libqt5-ukui-style/libqt5-ukui-style.pri) @@ -45,11 +45,13 @@ include(widget/widget.pri) SOURCES += \ qt5-ukui-platform-theme.cpp \ + platform-theme-fontdata.cpp \ main.cpp HEADERS += \ qt5-ukui-platform-theme.h \ - qt5-ukui-platformtheme_global.h + qt5-ukui-platformtheme_global.h \ + platform-theme-fontdata.h TRANSLATIONS += \ $$PWD/translations/qt5-ukui-platformtheme_zh_CN.ts \ diff --git a/qt5-ukui-platformtheme/widget/filedialog/debug.h b/qt5-ukui-platformtheme/widget/filedialog/debug.h index a3e6bf6..25b8fe4 100644 --- a/qt5-ukui-platformtheme/widget/filedialog/debug.h +++ b/qt5-ukui-platformtheme/widget/filedialog/debug.h @@ -2,10 +2,6 @@ #define PDEBUG_H #include -//#ifndef UseNativeFileDialog -//#define UseNativeFileDialog -//#endif - #define SERVICE "com.kylin.statusmanager.interface" #define PATH "/" #define INTERFACE "com.kylin.statusmanager.interface" diff --git a/qt5-ukui-platformtheme/widget/filedialog/kyfiledialog.cpp b/qt5-ukui-platformtheme/widget/filedialog/kyfiledialog.cpp index c232aef..92421bc 100644 --- a/qt5-ukui-platformtheme/widget/filedialog/kyfiledialog.cpp +++ b/qt5-ukui-platformtheme/widget/filedialog/kyfiledialog.cpp @@ -1,6 +1,4 @@ #include "debug.h" -#ifdef UseNativeFileDialog - #include "kyfiledialog.h" #include #include "ui_kyfiledialog.h" @@ -31,6 +29,9 @@ #include #include #include +#include +#include +#include #include #include "xatom-helper.h" #include @@ -68,11 +69,18 @@ KyNativeFileDialog::KyNativeFileDialog(QWidget *parent) mKyFileDialogUi = new Ui_KyFileDialog; - setStyle(nullptr); +// setStyle(nullptr); // m_fileSystemModel = new QFileSystemModel(); - connect(d_ptr.get()->m_timer, &QTimer::timeout, this, &KyNativeFileDialog::show); + connect(d_ptr.get()->m_timer, &QTimer::timeout, this, [&](){ +// pDebug << "timeout isActive:..........." << d_ptr.get()->m_timer->isActive(); + this->show(); + if(d_ptr.get()->m_timer->isActive()){ + pDebug << "timer stop...."; + d_ptr.get()->m_timer->stop(); + } + }); mKyFileDialogUi->setupUi(this); d_ptr.get()->m_container = mKyFileDialogUi->m_container; @@ -125,6 +133,8 @@ KyNativeFileDialog::KyNativeFileDialog(QWidget *parent) connect(getCurrentPage(), &Peony::DirectoryViewContainer::updateWindowLocationRequest, this, [=](const QString &uri, bool addToHistory, bool forceUpdate){ pDebug << "page updateWindowLocationRequest.....uri:" << uri << getCurrentUri() << forceUpdate; + if(uri == "") + return; QString s = uri; QString s1 = s.endsWith("/") ? s.remove(s.length() - 1, 1) : s; QString s2 = getCurrentUri(); @@ -283,6 +293,7 @@ KyNativeFileDialog::KyNativeFileDialog(QWidget *parent) refreshContainerSort(); updateMaximizeState(); onSwitchView(); + isTableModel(); m_model = new QStringListModel(); m_completer = new QCompleter(mKyFileDialogUi->m_fileNameEdit); @@ -303,6 +314,7 @@ KyNativeFileDialog::KyNativeFileDialog(QWidget *parent) KyNativeFileDialog::~KyNativeFileDialog() { + pDebug << "~~~~~~~~KyNativeFileDialog"; } @@ -332,7 +344,10 @@ Peony::FMWindowIface *KyNativeFileDialog::create(const QStringList &uris) const QStringList KyNativeFileDialog::getCurrentSelections() { - return containerView()->getSelections(); + if(containerView()) + return containerView()->getSelections(); + else + return QStringList(); } const QStringList KyNativeFileDialog::getCurrentSelectionsList() @@ -346,7 +361,9 @@ const QStringList KyNativeFileDialog::getCurrentSelectionsList() const QStringList KyNativeFileDialog::getCurrentAllFileUris() { - return containerView()->getAllFileUris(); + if(containerView()) + return containerView()->getAllFileUris(); + return QStringList(); } const QList> KyNativeFileDialog::getCurrentSelectionFileInfos() { @@ -365,8 +382,10 @@ void KyNativeFileDialog::setCurrentSelections(QStringList selections) foreach (QString str, selections) { list.append(Peony::FileUtils::urlEncode(str)); } - containerView()->setSelections(list); - pDebug << "get setCurrentSelections....:" << containerView()->getSelections(); + if(containerView()){ + containerView()->setSelections(list); + pDebug << "get setCurrentSelections....:" << containerView()->getSelections(); + } } Qt::SortOrder KyNativeFileDialog::getCurrentSortOrder() @@ -441,7 +460,8 @@ void KyNativeFileDialog::forceStopLoading() if (Peony::ClipboardUtils::isClipboardHasFiles()) { Peony::ClipboardUtils::clearClipboard(); - containerView()->repaintView(); + if(containerView()) + containerView()->repaintView(); } } @@ -474,7 +494,8 @@ void KyNativeFileDialog::setCurrentSelectionUris(const QStringList &uris) if (Peony::ClipboardUtils::isClipboardHasFiles()) { Peony::ClipboardUtils::clearClipboard(); - containerView()->repaintView(); + if(containerView()) + containerView()->repaintView(); } } @@ -490,12 +511,14 @@ void KyNativeFileDialog::setCurrentSortColumn (int sortColumn) void KyNativeFileDialog::editUri(const QString &uri) { - containerView()->editUri(uri); + if(containerView()) + containerView()->editUri(uri); } void KyNativeFileDialog::editUris(const QStringList &uris) { - containerView()->editUris(uris); + if(containerView()) + containerView()->editUris(uris); } bool KyNativeFileDialog::getFilterWorking() @@ -578,10 +601,15 @@ QUrl KyNativeFileDialog::directoryUrl() const void KyNativeFileDialog::goToUri(const QString &uri, bool addToHistory, bool forceUpdate) { pDebug << "goToUri....,,,,:" << uri << getCurrentUri(); - pDebug << "isShow......:" << (m_fileDialogHelper == nullptr); + if(uri.isEmpty() || uri == getCurrentUri()) + return; + + pDebug << "getCurrentUri....,,,,:" << getCurrentUri(); + pDebug << "isShow......:" << (m_fileDialogHelper == nullptr) << m_fileDialogHelper->isShow(); if(isInitialGoToUriNum || (m_fileDialogHelper != nullptr && m_fileDialogHelper->isShow())) { isInitialGoToUriNum = false; + getCurrentPage()->stopLoading(); if(uri.startsWith("search:///search_uris=")) getCurrentPage()->goToUri(uri, addToHistory, forceUpdate); else @@ -778,7 +806,7 @@ void KyNativeFileDialog::selectNameFilterByIndex(int index) pDebug << "selectNameFilterByIndex00000000000"; if (/*d->acceptMode == QFileDialog::AcceptSave &&*/ !newNameFilters.isEmpty() && (d->fileMode != QFileDialog::DirectoryOnly && d->fileMode != QFileDialog::Directory)) { QMimeDatabase db; - QString text = mKyFileDialogUi->m_fileNameEdit->text(); + QString text = copyEditText();//mKyFileDialogUi->m_fileNameEdit->text(); pDebug << "selectNameFilterByIndex text...." << text; pDebug << "selectNameFilterByIndex newNameFilters...." << newNameFilters; QStringList list = text.split("."); @@ -868,6 +896,7 @@ void KyNativeFileDialog::setAcceptMode(QFileDialog::AcceptMode mode) mKyFileDialogUi->m_newFolderButton->show(); mKyFileDialogUi->m_acceptButton->setText(tr("Save")); mKyFileDialogUi->m_rejectButton->setText(tr("Cancel")); + mKyFileDialogUi->m_acceptButton->setDefault(true); connect(mKyFileDialogUi->m_fileNameEdit, &QLineEdit::textChanged, this, &KyNativeFileDialog::onCurrentInputNameChanged); connect(mKyFileDialogUi->m_newFolderButton, &QPushButton::clicked, this, &KyNativeFileDialog::onNewFolder); } @@ -918,21 +947,23 @@ QFileDialog::FileMode KyNativeFileDialog::fileMode() void KyNativeFileDialog::setViewMode(ViewMode mode) { - pDebug << "setViewMode...." << mode << containerView()->viewId(); - if(mode == ViewMode::List && containerView()->viewId() != "List View") - { - this->getCurrentPage()->switchViewType("List View"); + if(containerView()){ + pDebug << "setViewMode...." << mode << containerView()->viewId(); + if(mode == ViewMode::List && containerView()->viewId() != "List View") + { + this->getCurrentPage()->switchViewType("List View"); + } + else if(mode == ViewMode::Icon && containerView()->viewId() != "Icon View") + this->getCurrentPage()->switchViewType("Icon View"); + onSwitchView(); } - else if(mode == ViewMode::Icon && containerView()->viewId() != "Icon View") - this->getCurrentPage()->switchViewType("Icon View"); - onSwitchView(); } KyNativeFileDialog::ViewMode KyNativeFileDialog::viewMode() const { // this->getCurrentPage()->switchViewType("List View"); - if(containerView()->viewId() == "List View") + if(containerView() && containerView()->viewId() == "List View") return ViewMode::List; return ViewMode::Icon; } @@ -1000,7 +1031,8 @@ QFileDialog::Options KyNativeFileDialog::options() const void KyNativeFileDialog::setCurrentInputName(const QString &name) { pDebug << "setCurrentInputName.........:" << name; - mKyFileDialogUi->m_fileNameEdit->setText(name); + m_copyEditText = name; +// mKyFileDialogUi->m_fileNameEdit->setText(name); QMimeDatabase db; const QString &suffix = db.suffixForFileName(name); if (suffix.isEmpty()) { @@ -1017,13 +1049,29 @@ void KyNativeFileDialog::onAcceptButtonClicked() return; } pDebug << "onAcceptButtonClicked:" << d->acceptMode << d->fileMode; - if(mKyFileDialogUi->m_fileNameEdit->text() != "") + pDebug << "onAcceptButtonClicked000 sfiles..........:" << getCurrentSelectionsList(); + pDebug << "onAcceptButtonClicked111 sfiles..........:" << selectedFiles(); + + if(d->fileMode == QFileDialog::ExistingFile || d->fileMode == QFileDialog::ExistingFiles || d->fileMode == QFileDialog::AnyFile) { - lineEditTextChange(mKyFileDialogUi->m_fileNameEdit->text()); + QList sFiles = selectedFiles(); + for (int i = 0; i < sFiles.length(); ++i) { + if(isDir(sFiles[i])) + { + pDebug << "gotouri666666" << "file://" + sFiles[i]; + goToUri(sFiles[i], true); + return; + } + } } - pDebug << "directoryUrl:" << directoryUrl() << directory(); + + if(copyEditText() != "") + { + lineEditTextChange(copyEditText()); + } + pDebug << "onAcceptButtonClicked directoryUrl:" << directoryUrl() << directory(); QList sFiles = selectedFiles(); - pDebug << "sfiles..........:" << sFiles; + pDebug << "onAcceptButtonClicked sfiles..........:" << sFiles; // pDebug << "getSelections........:" << containerView()->getSelections(); // pDebug << "uri:" << Peony::FileUtils::getTargetUri(getCurrentUri()); // pDebug << "uri1111111111:" << Peony::FileUtils::getParentUri(getCurrentUri()); @@ -1046,18 +1094,6 @@ void KyNativeFileDialog::onAcceptButtonClicked() } } - if(d->fileMode == QFileDialog::ExistingFile || d->fileMode == QFileDialog::ExistingFiles || (d->acceptMode == QFileDialog::AcceptOpen && d->fileMode == QFileDialog::AnyFile)) - { - for (int i = 0; i < sFiles.length(); ++i) { - if(isDir(sFiles[i])) - { - pDebug << "gotouri666666" << "file://" + sFiles[i]; - goToUri(sFiles[i], true); - return; - } - } - } - if (d->acceptMode == QFileDialog::AcceptSave) { if(!doSave(sFiles)) @@ -1084,35 +1120,34 @@ void KyNativeFileDialog::onAcceptButtonClicked() bool KyNativeFileDialog::saveMessageBox(QString name) { - QMessageBox *msg = new QMessageBox(QMessageBox::Warning, tr("Warning"), name + tr("exist, are you sure replace?"), QMessageBox::Ok | QMessageBox::No); - foreach (QAbstractButton* item, msg->buttons()) { - if(msg->standardButton(item) == QMessageBox::Ok){ - item->setText(tr("ok")); - msg->addButton(item, QMessageBox::YesRole); - connect(item, &QAbstractButton::clicked, [](bool b) - { - pDebug << "YesRole clicked......"; - return true; - }); - } - if(msg->standardButton(item) == QMessageBox::No){ - item->setText(tr("no")); - msg->addButton(item, QMessageBox::NoRole); - connect(item, &QAbstractButton::clicked, [](bool b) - { - pDebug << "NoRole clicked......"; - return false; - }); - } + if(QMessageBox::warning(this, tr("Warning"), name + " " + tr("exist, are you sure replace?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) + { + return true; } - msg->exec(); + return false; +} + +bool KyNativeFileDialog::checkSaveFileExsits(QString path) +{ + bool exists = false; + if(fileMode() == QFileDialog::Directory || fileMode() == QFileDialog::DirectoryOnly) + { + QDir dir(path); + exists = dir.exists(); + } + else{ + QFile file(path); + exists = file.exists(); + } + pDebug << "checkSaveFileExsits path...." << path << exists; + return exists; } bool KyNativeFileDialog::doSave(QStringList sFiles) { Q_D(KyNativeFileDialog); - QString file_name = mKyFileDialogUi->m_fileNameEdit->text(); + QString file_name = copyEditText(); bool suffixCheck = false; QStringList nameFilters = d->nameFilters; for (QString nameFilterList : nameFilters) { @@ -1164,13 +1199,20 @@ bool KyNativeFileDialog::doSave(QStringList sFiles) oldName.append('.' + suffix); setCurrentInputName(oldName); pDebug << "path///:" << directory().path() + "/" + oldName; - QFile file(directory().path() + "/" + oldName); - if(file.exists()) + if(checkSaveFileExsits(directory().path() + "/" + oldName)){ + if(!saveMessageBox(oldName)) + return false; break; + } if(filter == newNameFilters[newNameFilters.length() - 1]) { QString oldName = file_name; oldName.append('.' + mdb.suffixForFileName(newNameFilters[0])); + if(checkSaveFileExsits(directory().path() + "/" + oldName)){ + if(!saveMessageBox(oldName)) + return false; + break; + } setCurrentInputName(oldName); return true; } @@ -1179,11 +1221,23 @@ bool KyNativeFileDialog::doSave(QStringList sFiles) } else{ file_name.append('.' + m_fileDialogHelper->options()->defaultSuffix()); + if(checkSaveFileExsits(directory().path() + "/" + file_name)){ + if(!saveMessageBox(file_name)) + return false; + } setCurrentInputName(file_name); pDebug << "path///:" << directory().path() + "/" + file_name; } } } + else if(suffixCheck) + { + pDebug << "suffixCheck.....:" << suffixCheck << "path///:" << directory().path() + "/" + file_name; + if(checkSaveFileExsits(directory().path() + "/" + file_name)){ + if(!saveMessageBox(file_name)) + return false; + } + } return true; } @@ -1223,11 +1277,11 @@ bool KyNativeFileDialog::doOpen(QStringList sFiles) { Q_EMIT filesSelected(selectedUrls()); } - else if(mKyFileDialogUi->m_fileNameEdit->text() != "") + else if(copyEditText() != "") { QList urlList; pDebug << "directory path:" << directory().path() << directoryUrl().path(); - urlList.append(QUrl(directory().path() + "/" + mKyFileDialogUi->m_fileNameEdit->text())); + urlList.append(QUrl(directory().path() + "/" + copyEditText())); Q_EMIT filesSelected(urlList); } else @@ -1235,7 +1289,7 @@ bool KyNativeFileDialog::doOpen(QStringList sFiles) } else if(d->fileMode == QFileDialog::DirectoryOnly || d->fileMode == QFileDialog::Directory) { - if(mKyFileDialogUi->m_fileNameEdit->text() != "") + if(copyEditText() != "") { if(sFiles.isEmpty() || (!sFiles.isEmpty() && !isDir(sFiles[0]))) { @@ -1263,7 +1317,8 @@ bool KyNativeFileDialog::doOpen(QStringList sFiles) { urls << QUrl::fromLocalFile(Peony::FileUtils::urlDecode(uri)); } - pDebug << "select uri....:" << containerView()->getSelections(); + if(containerView()) + pDebug << "select uri....:" << containerView()->getSelections(); Q_EMIT filesSelected(urls); } @@ -1280,8 +1335,14 @@ void KyNativeFileDialog::onRejectButtonClicked() } bool KyNativeFileDialog::isDir(QString path) -{ - path = Peony::FileUtils::urlEncode(path); +{ + auto fileSymLinkInfo = Peony::FileInfo::fromUri(path); + if(fileSymLinkInfo->isSymbolLink()) { + path = fileSymLinkInfo->symlinkTarget(); + } + else + path = Peony::FileUtils::urlEncode(path); + QFile file(path); QFileInfo fileInfo(file); pDebug << "isDir path1111:" << path << fileInfo.isDir() << Peony::FileUtils::isFileDirectory(path) << Peony::FileUtils::getFileIsFolder(path);; @@ -1339,7 +1400,7 @@ void KyNativeFileDialog::onSwitchView() void KyNativeFileDialog::updateWindowState() { Q_D(KyNativeFileDialog); - pDebug << "updateWindowState.............." << getCurrentUri() << directory() << directoryUrl() << mKyFileDialogUi->m_fileNameEdit->text(); + pDebug << "updateWindowState.............." << getCurrentUri() << directory() << directoryUrl() << mKyFileDialogUi->m_fileNameEdit->text() << copyEditText(); //mKyFileDialogUi->m_fileNameEdit->setText(""); pDebug << "updateWindowState m_searchMode.............." <m_toParentButton->setEnabled(getCurrentPage()->canCdUp()); updateStatusBar(); pDebug << "updateWindowState 44444"; - lineEditTextChange(mKyFileDialogUi->m_fileNameEdit->text()); + lineEditTextChange(copyEditText()); pDebug << "updateWindowState 55555555555555555555" << uri; } @@ -1385,7 +1446,14 @@ QString KyNativeFileDialog::selectName() QString nameStr = ""; for(int i = 0; i < selectList.length(); i++) { - pDebug << "selectName ....i:" << i << Peony::FileUtils::getFileDisplayName(selectList[i]); + pDebug << "selectName ....i:" << i << Peony::FileUtils::getFileDisplayName(selectList[i]) << isDir(selectList[i]); + if(acceptMode() == QFileDialog::AcceptSave && isDir(selectList[i])){ + continue; + } + if(acceptMode() == QFileDialog::AcceptOpen && (fileMode() == QFileDialog::ExistingFile || + fileMode() == QFileDialog::ExistingFiles || fileMode() == QFileDialog::AnyFile) && isDir(selectList[i])){ + continue; + } QString str = Peony::FileUtils::getFileDisplayName(selectList[i]);//Peony::FileUtils::urlDecode(selectList[i]); QString name = ""; if(selectList.length() == 1) @@ -1396,6 +1464,16 @@ QString KyNativeFileDialog::selectName() name += "\"" + str.split("/").last() + "\""; nameStr += name; } + + if(acceptMode() == QFileDialog::AcceptSave){ + for(int i = 0; i < selectList.length(); i++) { + if(isDir(selectList[i])) { + mKyFileDialogUi->m_acceptButton->setText(tr("Open")); + return nameStr; + } + } + mKyFileDialogUi->m_acceptButton->setText(tr("Save")); + } return nameStr; } @@ -1433,12 +1511,15 @@ void KyNativeFileDialog::containerMenuRequest(const QPoint &pos) void KyNativeFileDialog::delayShow() { Q_D(const KyNativeFileDialog); + //QTBUG48248 借鉴kde plasma-integration里用的QTimer + pDebug << "delayShow start..........."; d->m_timer->start(); } void KyNativeFileDialog::discardDelayedShow() { Q_D(const KyNativeFileDialog); + pDebug << "discardDelayedShow stop..........."; d->m_timer->stop(); } @@ -1576,13 +1657,15 @@ void KyNativeFileDialog::updateAcceptButtonState() { if(d->fileMode != QFileDialog::Directory && d->fileMode != QFileDialog::DirectoryOnly) { + mKyFileDialogUi->m_acceptButton->setEnabled(!(getCurrentSelectionsList().length() == 0)); + return; bool isSelectFile = false; - if(mKyFileDialogUi->m_fileNameEdit->text() == "") - mKyFileDialogUi->m_acceptButton->setEnabled(false); + if(copyEditText() == "") + mKyFileDialogUi->m_acceptButton->setEnabled(!(getCurrentSelectionsList().length() == 0)); - if(mKyFileDialogUi->m_fileNameEdit->text() != "") + if(copyEditText() != "") { - QString text = mKyFileDialogUi->m_fileNameEdit->text(); + QString text = copyEditText(); QStringList list = text.split("\""); pDebug << "list234565432............" << list; for (int i = list.length() - 1; i >= 0; i--) { @@ -1638,9 +1721,9 @@ void KyNativeFileDialog::updateAcceptButtonState() else { bool isSelectFile = true; - if(mKyFileDialogUi->m_fileNameEdit->text() != "") + if(copyEditText() != "") { - QString text = mKyFileDialogUi->m_fileNameEdit->text(); + QString text = copyEditText(); QStringList list = text.split("\""); pDebug << "list0000............" << list; for (int i = list.length() - 1; i >= 0; i--) { @@ -1680,7 +1763,11 @@ void KyNativeFileDialog::updateAcceptButtonState() } else { - if(mKyFileDialogUi->m_fileNameEdit->text() == "") + if(getCurrentSelectionsList().length() != 0){ + mKyFileDialogUi->m_acceptButton->setEnabled(true); + return; + } + if(copyEditText() == "") mKyFileDialogUi->m_acceptButton->setEnabled(false); else mKyFileDialogUi->m_acceptButton->setEnabled(true); @@ -1692,7 +1779,7 @@ void KyNativeFileDialog::updateAcceptButtonState() void KyNativeFileDialog::onCurrentInputNameChanged() { Q_D(KyNativeFileDialog); - d->currentInputName = mKyFileDialogUi->m_fileNameEdit->text(); + d->currentInputName = copyEditText(); updateAcceptButtonState(); } @@ -1798,6 +1885,7 @@ void KyNativeFileDialog::setSearchMode(bool mode) void KyNativeFileDialog::lineEditTextChange(QString text) { + m_copyEditText = text; if(m_searchMode) return; QString url; @@ -1813,13 +1901,24 @@ void KyNativeFileDialog::lineEditTextChange(QString text) url.remove(url.length() - 1, 1); pDebug << "parentPath:" << parentPath; + pDebug << "getCurrentSelections......:" << getCurrentSelectionsList() << text; - if(!text.contains("\"")) - { + if(!text.contains("\""))//输入框中只有1个文件 + { if ((parentPath.startsWith("trash://") || parentPath.startsWith("recent://") || parentPath.startsWith("computer://") || parentPath.startsWith("favorite://") || parentPath.startsWith("filesafe://")) && getCurrentSelections().length() > 0) { + for(int i = 0; i < getCurrentSelections().length(); i++) + { + QString targetUri = Peony::FileUtils::getTargetUri(getCurrentSelections()[i]); + Peony::FileInfo fileInfo(targetUri); + pDebug << "text:" << text << "displayName:" << fileInfo.displayName(); + if(fileInfo.displayName() == text){ + updateAcceptButtonState(); + return; + } + } QString targetUri = Peony::FileUtils::getTargetUri(getCurrentSelections()[0]); QString targetPath = Peony::FileUtils::urlDecode(targetUri); pDebug << "getTargetUri uri....." << targetUri; @@ -1836,8 +1935,16 @@ void KyNativeFileDialog::lineEditTextChange(QString text) } else { - pDebug << "Peony::FileUtils::isFileExsit:" << (parentPath + "/" + text) << Peony::FileUtils::isFileExsit(parentPath + "/" + text); + pDebug << "Peony::FileUtils::isFileExsit123:" << (parentPath + "/" + text) << Peony::FileUtils::isFileExsit(parentPath + "/" + text); // pDebug << "Peony::FileUtils::isFileExsit:" << (parentPath + "/" + text) << Peony::FileUtils::isFileExsit(parentPath + "/" + text); + for(int i = 0; i < getCurrentSelections().length(); i++) + { + if(Peony::FileUtils::getFileDisplayName(getCurrentSelections()[i]) == text){ + updateAcceptButtonState(); + return; + } + } + if(Peony::FileUtils::isFileExsit(parentPath + "/" + text)){ pDebug << "file exists...."; //m_container选择指定文件 @@ -1845,7 +1952,8 @@ void KyNativeFileDialog::lineEditTextChange(QString text) selectList.append(parentPath + "/" + text); pDebug << "selectList...1111111" << selectList; setCurrentSelections(selectList); - pDebug << "selectList...22222222222" << containerView()->getSelections(); + if(containerView()) + pDebug << "selectList...22222222222" << containerView()->getSelections(); updateAcceptButtonState(); return; } @@ -1865,6 +1973,31 @@ void KyNativeFileDialog::lineEditTextChange(QString text) || parentPath.startsWith("computer://") || parentPath.startsWith("favorite://") || parentPath.startsWith("filesafe://"))) { + QStringList list = text.split("\""); + pDebug << "listttt1111............" << list; + for (int i = list.length() - 1; i >= 0; i--) { + if(list[i] == "" || list[i] == " ") + list.removeAt(i); + } + QStringList displayNameList; + for(int i = 0; i < getCurrentSelections().length(); i++) + { + QString targetUri = Peony::FileUtils::getTargetUri(getCurrentSelections()[i]); + Peony::FileInfo fileInfo(targetUri); + pDebug << "text:" << text << "displayName:" << fileInfo.displayName(); + displayNameList.append(fileInfo.displayName()); + } + pDebug << "list:" << list; + pDebug << "displayNameList:" << displayNameList; + for(int i = 0; i < list.length(); i++){ + if(!displayNameList.contains(list[i])) + break; + else if(i == list.length() - 1){ + updateAcceptButtonState(); + return; + } + } + QStringList selectList; foreach (QString str, getCurrentSelections()) { @@ -1892,6 +2025,24 @@ void KyNativeFileDialog::lineEditTextChange(QString text) } pDebug << "listtttt22222222..............:" << list; + QStringList displayNameList; + for(int i = 0; i < getCurrentSelections().length(); i++) + { + QString displayName = Peony::FileUtils::getFileDisplayName(getCurrentSelections()[i]); + displayNameList.append(displayName); + } + pDebug << "list:" << list; + pDebug << "displayNameList:" << displayNameList; + for(int i = 0; i < list.length(); i++){ + if(!displayNameList.contains(list[i])) + break; + else if(i == list.length() - 1){ + updateAcceptButtonState(); + return; + } + } + + pDebug << "listtttttt3333333........................."; foreach (QString str, list) { if(str.length() > 0 && str[0] == "\"") str = str.remove(0, 1); @@ -2026,14 +2177,16 @@ void KyNativeFileDialog::setShortCuts() auto maxAction = new QAction(this); maxAction->setShortcut(QKeySequence(Qt::Key_F11)); connect(maxAction, &QAction::triggered, this, [=]() { - //showFullScreen has some issue, change to showMaximized, fix #20043 - mKyFileDialogUi->m_pathbar->cancelEdit(); - if (!this->isMaximized()) { - this->showMaximized(); - } else { - this->showNormal(); + if(!m_istableModel){ + //showFullScreen has some issue, change to showMaximized, fix #20043 + mKyFileDialogUi->m_pathbar->cancelEdit(); + if (!this->isMaximized()) { + this->showMaximized(); + } else { + this->showNormal(); + } + updateMaximizeState(); } - updateMaximizeState(); }); addAction(maxAction); @@ -2192,6 +2345,8 @@ void KyNativeFileDialog::setShortCuts() void KyNativeFileDialog::initialViewId() { + if(!containerView()) + return; int zoomLevel = containerView()->currentZoomLevel(); auto viewId = Peony::DirectoryViewFactoryManager2::getInstance()->getDefaultViewId(zoomLevel, getCurrentUri()); @@ -2199,6 +2354,37 @@ void KyNativeFileDialog::initialViewId() beginSwitchView(viewId); } +QString KyNativeFileDialog::copyEditText() +{ + return m_copyEditText; +} + +void KyNativeFileDialog::isTableModel() +{ + QDBusInterface *interFace = new QDBusInterface(SERVICE, PATH, INTERFACE, QDBusConnection::sessionBus()); + if(interFace->isValid()){ + connect(interFace, SIGNAL(mode_change_signal(bool)), this, SLOT(updateTableModel(bool))); + } + QDBusMessage message = QDBusMessage::createMethodCall(SERVICE, PATH, INTERFACE, "get_current_tabletmode"); + QDBusMessage ret = QDBusConnection::sessionBus().call(message); + if (ret.type() != QDBusMessage::ReplyMessage) + { + //从返回参数获取返回值 + pDebug << "complex type failed!"; + updateTableModel(false); + } + else + { + updateTableModel(ret.arguments()[0].value()); + } +} + +void KyNativeFileDialog::updateTableModel(bool tableModel) +{ + m_istableModel = tableModel; + mKyFileDialogUi->m_maximizeAndRestore->setVisible(!tableModel); +} + KyFileDialogHelper::KyFileDialogHelper() : QPlatformFileDialogHelper(), mKyFileDialog(new KyNativeFileDialog) { mKyFileDialog->setHelper(this); @@ -2206,8 +2392,10 @@ KyFileDialogHelper::KyFileDialogHelper() : QPlatformFileDialogHelper(), mKyFileD pDebug << "KyFileDialogHelper........." << (options() == nullptr); connect(mKyFileDialog, &KyNativeFileDialog::currentChanged, this, &KyFileDialogHelper::currentChanged); connect(mKyFileDialog, &KyNativeFileDialog::directoryEntered, this, &KyFileDialogHelper::directoryEntered); - connect(mKyFileDialog, &KyNativeFileDialog::fileSelected, this, &KyFileDialogHelper::fileSelected); - connect(mKyFileDialog, &KyNativeFileDialog::filesSelected, this, &KyFileDialogHelper::filesSelected); + //QFileDialog::accept()里_q_emitUrlSelected会发送fileSelected信号 这里会导致发两次fileSelected的信号 + // connect(mKyFileDialog, &KyNativeFileDialog::fileSelected, this, &KyFileDialogHelper::fileSelected); + //QFileDialog::accept()里_q_emitUrlsSelected会发送filesSelected信号 这里会导致发两次filesSelected的信号 + // connect(mKyFileDialog, &KyNativeFileDialog::filesSelected, this, &KyFileDialogHelper::filesSelected); connect(mKyFileDialog, &KyNativeFileDialog::filterSelected, this, &KyFileDialogHelper::filterSelected); connect(mKyFileDialog, &QDialog::accepted, this, &KyFileDialogHelper::accept); connect(mKyFileDialog, &QDialog::rejected, this, &KyFileDialogHelper::reject); @@ -2216,11 +2404,18 @@ KyFileDialogHelper::KyFileDialogHelper() : QPlatformFileDialogHelper(), mKyFileD KyFileDialogHelper::~KyFileDialogHelper() { + pDebug << "~~~~~~~~KyFileDialogHelper"; + ///不可以析构 普通函数里QFileDialog::show不显示和QFiledialog->show()会显示 析构的话BT下载工具打开不显示界面 +// if(mKyFileDialog){ +// mKyFileDialog->deleteLater(); +// mKyFileDialog = nullptr; +// } } void KyFileDialogHelper::exec() { + pDebug << "KyFileDialogHelper::exec.............."; mKyFileDialog->discardDelayedShow(); mKyFileDialog->exec(); } @@ -2249,7 +2444,19 @@ bool KyFileDialogHelper::show(Qt::WindowFlags windowFlags, Qt::WindowModality wi for(QFileDialog *fd : p->findChildren()){ if(options()->windowTitle() == fd->windowTitle()){ pDebug << "filedoalog set parent...." << fd->geometry(); - mKyFileDialog->setParent(fd, windowFlags); + if(mKyFileDialog->parentWidget() != fd){ + ///设置parent是QFiledialog 之前设置的是p 会有问题 showevent里有时候会找不到对应name的 + mKyFileDialog->setParent(fd, windowFlags); + } + pDebug << "filediaog directory000...." << fd->directory(); + pDebug << "filedialog select000....." << fd->selectedFiles(); + pDebug << "filedialog selectUrls000....." << fd->selectedUrls(); + pDebug << "filedialog directoryUrl000....." << fd->directoryUrl(); + if(fd->directory().exists()) + mKyFileDialog->setDirectory(fd->directory()); + +// if(fd->directoryUrl().) + // for(QPushButton *btn : mKyFileDialog->findChildren()) // { // if(btn->objectName() == "acceptButton") @@ -2336,6 +2543,10 @@ void KyFileDialogHelper::viewInitialFinished() if(m_viewInitialFinished) return; pDebug << "viewInitialFinished...."; + QTimer::singleShot(100, this, [this](){ + pDebug << "viewport update1111111......."; + mKyFileDialog->mKyFileDialogUi->m_sider->viewport()->update(); + }); QTimer::singleShot(500, this, [this](){ @@ -2396,15 +2607,26 @@ void KyFileDialogHelper::viewInitialFinished() } pDebug << "initially selectirectory:" << selectirectory.toString() << selectirectory.path() << QFile::exists(selectirectory.path()) << Peony::FileUtils::isFileExsit(selectirectory.toString()); - + pDebug << "current path....." << mKyFileDialog->getCurrentUri(); if(strList.length() <= 0 && Peony::FileUtils::isFileExsit(selectirectory.toString()))//QFile::exists(selectirectory.path())) { - mKyFileDialog->setDirectoryUrl(selectirectory); + QString cStr = mKyFileDialog->getCurrentUri(); + QString sStr = selectirectory.toString(); + + if(cStr.endsWith("/")) + cStr = cStr.remove(cStr.length() - 1, 1); + if(sStr.endsWith("/")) + sStr = sStr.remove(sStr.length() - 1, 1); + pDebug << "cStr...." << cStr << "sStr...." << sStr; + if(cStr != sStr) + mKyFileDialog->setDirectoryUrl(selectirectory); } mKyFileDialog->intiContainerSort(); mKyFileDialog->initialViewId(); - + pDebug << "viewport update222222......."; + mKyFileDialog->mKyFileDialogUi->m_sider->viewport()->update(); +// mKyFileDialog->refresh(); m_viewInitialFinished = true; }); } @@ -2454,7 +2676,7 @@ QList KyFileDialogHelper::selectedFiles() const { QList urlList = mKyFileDialog->selectedUrls(); if((options()->fileMode() == QFileDialogOptions::Directory || options()->fileMode() == QFileDialogOptions::DirectoryOnly) && - mKyFileDialog->mKyFileDialogUi->m_fileNameEdit->text() == "" && m_viewInitialFinished) + mKyFileDialog->copyEditText() == "" && m_viewInitialFinished) { if (!mKyFileDialog->getCurrentPage()) { return QList(); @@ -2486,8 +2708,8 @@ QList KyFileDialogHelper::selectedFiles() const QString path = mKyFileDialog->getCurrentUri(); if(!path.endsWith("/")) path += "/"; - pDebug << "selected filesss...:" << path + mKyFileDialog->mKyFileDialogUi->m_fileNameEdit->text(); - urlList.append(QUrl(path + mKyFileDialog->mKyFileDialogUi->m_fileNameEdit->text())); + pDebug << "selected filesss...:" << path + mKyFileDialog->copyEditText(); + urlList.append(QUrl(path + mKyFileDialog->copyEditText())); return urlList; } } @@ -2497,7 +2719,7 @@ QList KyFileDialogHelper::selectedFiles() const QString path = mKyFileDialog->getCurrentUri(); if(!path.endsWith("/")) path += "/"; - path += mKyFileDialog->mKyFileDialogUi->m_fileNameEdit->text(); + path += mKyFileDialog->copyEditText(); if(path.startsWith("file:///")) path = path.remove(0,7); pDebug << "save selectedFiles00000..........:" << path; @@ -2545,5 +2767,3 @@ bool KyFileDialogHelper::isSupportedUrl(const QUrl &url) const return url.isLocalFile(); } - -#endif diff --git a/qt5-ukui-platformtheme/widget/filedialog/kyfiledialog.h b/qt5-ukui-platformtheme/widget/filedialog/kyfiledialog.h index 2f2562f..90c44d4 100644 --- a/qt5-ukui-platformtheme/widget/filedialog/kyfiledialog.h +++ b/qt5-ukui-platformtheme/widget/filedialog/kyfiledialog.h @@ -1,5 +1,4 @@ #include "debug.h" -#ifdef UseNativeFileDialog #ifndef KYNATIVEFILEDIALOG_H #define KYNATIVEFILEDIALOG_H #include @@ -150,6 +149,11 @@ public: void initialViewId(); + void delayShow(); + + void discardDelayedShow(); + + QString copyEditText(); Q_SIGNALS: void switchViewRequest(const QString &viewId); @@ -171,14 +175,13 @@ public Q_SLOTS: void updateWindowState(); QString selectName(); void updateStatusBar(); - void delayShow(); - void discardDelayedShow(); void onNewFolder(); void setSortType(); void searchButtonClicked(); void setSearchMode(bool mode); void lineEditTextChange(QString text); void containerMenuRequest(const QPoint &pos); + void updateTableModel(bool tableMode); protected: void resizeEvent(QResizeEvent *e); @@ -195,6 +198,8 @@ private: void onCurrentInputNameChanged(); void handleEnterPressed(); void updateAcceptButtonState(); + bool checkSaveFileExsits(QString path); + void isTableModel(); private: bool m_searchMode = false; @@ -208,6 +213,8 @@ private: QString m_lastSearchPath; bool m_isClearSearchKey = false; QStringListModel *m_model = nullptr; + QString m_copyEditText; + bool m_istableModel = false; }; @@ -264,4 +271,3 @@ private: #endif // KYNATIVEFILEDIALOG_H -#endif diff --git a/qt5-ukui-platformtheme/widget/filedialog/kyfiledialogprivate.cpp b/qt5-ukui-platformtheme/widget/filedialog/kyfiledialogprivate.cpp index e827cc1..2715590 100644 --- a/qt5-ukui-platformtheme/widget/filedialog/kyfiledialogprivate.cpp +++ b/qt5-ukui-platformtheme/widget/filedialog/kyfiledialogprivate.cpp @@ -1,5 +1,4 @@ #include "debug.h" -#ifdef UseNativeFileDialog #include "kyfiledialogprivate.h" #include @@ -57,4 +56,3 @@ QStringList KyNativeFileDialogPrivate::typedFiles() */ return QStringList(); } -#endif diff --git a/qt5-ukui-platformtheme/widget/filedialog/kyfiledialogprivate.h b/qt5-ukui-platformtheme/widget/filedialog/kyfiledialogprivate.h index 9a4cf2a..b2d42c9 100644 --- a/qt5-ukui-platformtheme/widget/filedialog/kyfiledialogprivate.h +++ b/qt5-ukui-platformtheme/widget/filedialog/kyfiledialogprivate.h @@ -1,5 +1,4 @@ #include "debug.h" -#ifdef UseNativeFileDialog #ifndef KYNATIVEFILEDIALOGPRIVATE_H #define KYNATIVEFILEDIALOGPRIVATE_H @@ -29,7 +28,6 @@ private: }; #endif // KYNATIVEFILEDIALOGPRIVATE_H -#endif /* KyNativeFileDialogPrivate::KyNativeFileDialogPrivate() { diff --git a/qt5-ukui-platformtheme/widget/filedialog/menutoolbutoon.cpp b/qt5-ukui-platformtheme/widget/filedialog/menutoolbutoon.cpp index c4d62d3..5823a97 100644 --- a/qt5-ukui-platformtheme/widget/filedialog/menutoolbutoon.cpp +++ b/qt5-ukui-platformtheme/widget/filedialog/menutoolbutoon.cpp @@ -1,6 +1,4 @@ #include "debug.h" -#ifdef UseNativeFileDialog - #include "menutoolbutoon.h" #include #include @@ -75,4 +73,3 @@ void ToolButtonStyle::drawPrimitive(QStyle::PrimitiveElement element, const QSty } return qApp->style()->drawPrimitive(element, option, painter, widget); } -#endif diff --git a/qt5-ukui-platformtheme/widget/filedialog/menutoolbutoon.h b/qt5-ukui-platformtheme/widget/filedialog/menutoolbutoon.h index 2f01851..5e42d13 100644 --- a/qt5-ukui-platformtheme/widget/filedialog/menutoolbutoon.h +++ b/qt5-ukui-platformtheme/widget/filedialog/menutoolbutoon.h @@ -1,5 +1,4 @@ #include "debug.h" -#ifdef UseNativeFileDialog #ifndef MENUTOOLBUTTON_H #define MENUTOOLBUTTON_H @@ -36,4 +35,3 @@ class ToolButtonStyle : public QProxyStyle void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr) const override; }; #endif // MENUTOOLBUTTON_H -#endif diff --git a/qt5-ukui-platformtheme/widget/filedialog/pathbar.cpp b/qt5-ukui-platformtheme/widget/filedialog/pathbar.cpp index 491e671..35ff1b1 100644 --- a/qt5-ukui-platformtheme/widget/filedialog/pathbar.cpp +++ b/qt5-ukui-platformtheme/widget/filedialog/pathbar.cpp @@ -1,5 +1,4 @@ #include "debug.h" -#ifdef UseNativeFileDialog #include "pathbar.h" #include @@ -74,4 +73,3 @@ void FileDialogPathBar::updateTableModel(bool isTable) } pDebug << "m_pathBar height1111:" << m_pathBar->height() << this->height(); } -#endif diff --git a/qt5-ukui-platformtheme/widget/filedialog/pathbar.h b/qt5-ukui-platformtheme/widget/filedialog/pathbar.h index 4f8e60d..daff076 100644 --- a/qt5-ukui-platformtheme/widget/filedialog/pathbar.h +++ b/qt5-ukui-platformtheme/widget/filedialog/pathbar.h @@ -1,5 +1,4 @@ #include "debug.h" -#ifdef UseNativeFileDialog #ifndef PATHBAR_H #define PATHBAR_H @@ -28,4 +27,3 @@ private: Peony::AdvancedLocationBar *m_pathBar = nullptr; }; #endif // PATHBAR_H -#endif diff --git a/qt5-ukui-platformtheme/widget/filedialog/sidebar.cpp b/qt5-ukui-platformtheme/widget/filedialog/sidebar.cpp index ba3b9e6..a510a17 100644 --- a/qt5-ukui-platformtheme/widget/filedialog/sidebar.cpp +++ b/qt5-ukui-platformtheme/widget/filedialog/sidebar.cpp @@ -1,6 +1,4 @@ #include "debug.h" -#ifdef UseNativeFileDialog - #include "sidebar.h" #include #include @@ -77,7 +75,7 @@ FileDialogSideBar::FileDialogSideBar(QWidget *parent) : QTreeView(parent) header()->setStretchLastSection(false); header()->hide(); - this->verticalScrollBar()->setProperty("drawScrollBarGroove", true); + this->verticalScrollBar()->setProperty("drawScrollBarGroove", false); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); this->setFrameStyle(QFrame::NoFrame); setSortingEnabled(true); @@ -453,4 +451,3 @@ void SideBarStyle::drawControl(QStyle::ControlElement element, const QStyleOptio return qApp->style()->drawControl(element, &opt, painter, widget); } } -#endif diff --git a/qt5-ukui-platformtheme/widget/filedialog/sidebar.h b/qt5-ukui-platformtheme/widget/filedialog/sidebar.h index c5cf915..7ff3e23 100644 --- a/qt5-ukui-platformtheme/widget/filedialog/sidebar.h +++ b/qt5-ukui-platformtheme/widget/filedialog/sidebar.h @@ -1,6 +1,4 @@ #include "debug.h" -#ifdef UseNativeFileDialog - #ifndef SIDEBAR_H #define SIDEBAR_H #include @@ -72,4 +70,3 @@ public: void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const override; }; #endif // SIDEBAR_H -#endif diff --git a/qt5-ukui-platformtheme/widget/filedialog/ui_kyfiledialog.cpp b/qt5-ukui-platformtheme/widget/filedialog/ui_kyfiledialog.cpp index dda9247..c69c627 100644 --- a/qt5-ukui-platformtheme/widget/filedialog/ui_kyfiledialog.cpp +++ b/qt5-ukui-platformtheme/widget/filedialog/ui_kyfiledialog.cpp @@ -1,6 +1,4 @@ #include "debug.h" -#ifdef UseNativeFileDialog - #include "ui_kyfiledialog.h" #include #include "kyfiledialog.h" @@ -61,7 +59,7 @@ void Ui_KyFileDialog::initSortMenu(QDialog *mKyFileDialog) m_sortButton->setMenu(m_sortMenu); m_sortButton->setPopupMode(QToolButton::InstantPopup); m_sortButton->setAutoRaise(true); - m_sortButton->setFixedWidth(57); + m_sortButton->setFixedSize(QSize(57, 40)); m_sortButton->setIconSize(QSize(16, 16)); } @@ -71,7 +69,7 @@ void Ui_KyFileDialog::initModeMenu(QDialog *mKyFileDialog) m_modeButton = new MenuToolButton(); m_modeButton->setPopupMode(QToolButton::InstantPopup); m_modeButton->setAutoRaise(true); - m_modeButton->setFixedWidth(57); + m_modeButton->setFixedSize(QSize(57, 40)); m_modeButton->setIconSize(QSize(16, 16)); m_modeMenu = new QMenu(m_modeButton); @@ -95,18 +93,14 @@ void Ui_KyFileDialog::initSiderBar(QDialog *mKyFileDialog) void Ui_KyFileDialog::initHeaderBar(QDialog *mKyFileDialog) { m_hHeaderLayout = new QHBoxLayout(); - m_hHeaderLayout->setContentsMargins(4,5,4,5); initModeMenu(mKyFileDialog); initSortMenu(mKyFileDialog); - m_hHeaderLayout->setContentsMargins(0,0,0,0); + m_hHeaderLayout->setContentsMargins(0,0,8,0); m_hHeaderLayout->setObjectName(QString::fromUtf8("hboxLayout")); m_backButton = new QToolButton(); m_forwardButton = new QToolButton(); m_toParentButton = new QToolButton(); - m_backButton->setObjectName("m_backButton"); - m_forwardButton->setObjectName("m_forwardButton"); - m_toParentButton->setObjectName("m_toParentButton"); m_pathbarWidget = new FileDialogPathBar();//new Peony::AdvancedLocationBar(mKyFileDialog);// m_pathbar = m_pathbarWidget->getPathBar(); @@ -208,8 +202,7 @@ void Ui_KyFileDialog::setupUi(QDialog *mKyFileDialog) m_gridLayout = new QGridLayout(mKyFileDialog); m_gridLayout->setObjectName(QString::fromUtf8("gridLayout")); - m_container = new Peony::DirectoryViewContainer(mKyFileDialog); - m_container->setObjectName("container"); + m_container = new Peony::DirectoryViewContainer(); m_frame = new QFrame(); vboxLayout = new QVBoxLayout(); @@ -221,12 +214,13 @@ void Ui_KyFileDialog::setupUi(QDialog *mKyFileDialog) vboxLayout->addSpacing(8); vboxLayout->setObjectName(QString::fromUtf8("vboxLayout")); - vboxLayout->setContentsMargins(0, 0, 8, 0); + vboxLayout->setContentsMargins(0, 0, 0, 0); vboxLayout->addLayout(m_hHeaderLayout); - vboxLayout->addSpacing(12); - m_upSeperate = new QFrame(); + vboxLayout->addSpacing(6); + m_upSeperate = new QFrame(mKyFileDialog); m_upSeperate->setFrameShape(QFrame::HLine); + m_upSeperate->setFrameShadow(QFrame::Plain); vboxLayout->addWidget(m_upSeperate); vboxLayout->addSpacing(6); vboxLayout->addWidget(m_container); @@ -235,8 +229,9 @@ void Ui_KyFileDialog::setupUi(QDialog *mKyFileDialog) vboxLayout->addLayout(m_hLineEditLayout); vboxLayout->addSpacing(16); - m_downSeperate = new QFrame(); + m_downSeperate = new QFrame(mKyFileDialog); m_downSeperate->setFrameShape(QFrame::HLine); + m_downSeperate->setFrameShadow(QFrame::Plain); vboxLayout->addWidget(m_downSeperate); vboxLayout->addSpacing(16); @@ -269,4 +264,3 @@ void Ui_KyFileDialog::setupUi(QDialog *mKyFileDialog) m_gridLayout->addWidget(m_splitter); m_gridLayout->setContentsMargins(0,0,0,0); } -#endif diff --git a/qt5-ukui-platformtheme/widget/filedialog/ui_kyfiledialog.h b/qt5-ukui-platformtheme/widget/filedialog/ui_kyfiledialog.h index 44c62fd..57fb945 100644 --- a/qt5-ukui-platformtheme/widget/filedialog/ui_kyfiledialog.h +++ b/qt5-ukui-platformtheme/widget/filedialog/ui_kyfiledialog.h @@ -1,6 +1,4 @@ #include "debug.h" -#ifdef UseNativeFileDialog - #ifndef UI_KYFILEDIALOG_H #define UI_KYFILEDIALOG_H #include @@ -100,4 +98,3 @@ private: void intiBtnLayout(QDialog *mKyFileDialog); }; #endif // UI_KYFILEDIALOG_H -#endif diff --git a/qt5-ukui-platformtheme/widget/messagebox/message-box.cpp b/qt5-ukui-platformtheme/widget/messagebox/message-box.cpp index 400aab1..41f4f00 100644 --- a/qt5-ukui-platformtheme/widget/messagebox/message-box.cpp +++ b/qt5-ukui-platformtheme/widget/messagebox/message-box.cpp @@ -32,8 +32,6 @@ #include #include #include -#include "ukuistylehelper/ukuistylehelper.h" -#include "windowmanager/windowmanager.h" #include "private/qlabel_p.h" #include "private/qdialog_p.h" @@ -208,8 +206,10 @@ QPixmap MessageBox::iconPixmap() const void MessageBox::setIconPixmap(const QPixmap &pixmap) { Q_D(MessageBox); - if (!pixmap.isNull()) - d->mIconLabel->setPixmap(pixmap.scaled(d->mIconSize, d->mIconSize)); + if (!pixmap.isNull()){ + d->mIconLabel->setAlignment(Qt::AlignVCenter); + d->mIconLabel->setPixmap(pixmap); + } d->mIcon = QMessageBox::NoIcon; } @@ -491,11 +491,11 @@ void MessageBox::setWindowModality(Qt::WindowModality windowModality) { QDialog::setWindowModality(windowModality); - if (parentWidget() && windowModality == Qt::WindowModal) { - setParent(parentWidget(), Qt::Sheet); - } else { - setParent(parentWidget(), Qt::Dialog); - } +// if (parentWidget() && windowModality == Qt::WindowModal) { +// setParent(parentWidget(), Qt::Sheet); +// } else { +// setParent(parentWidget(), Qt::Dialog); +// } setDefaultButton(d_func()->mDefaultButton); } @@ -707,6 +707,7 @@ MessageBoxPrivate::MessageBoxPrivate() : mCheckbox(nullptr), mEscapeButton(nullp MessageBoxPrivate::~MessageBoxPrivate() { + /* if (nullptr != mLabel) { delete mLabel; } @@ -726,6 +727,7 @@ MessageBoxPrivate::~MessageBoxPrivate() if (nullptr != mDetailButton) { delete mDetailButton; } + */ } void MessageBoxPrivate::init(const QString &title, const QString &text) @@ -741,7 +743,6 @@ void MessageBoxPrivate::init(const QString &title, const QString &text) mIconLabel = new QLabel; mIconLabel->setObjectName(QLatin1String("ukui_msgbox_icon_label")); mIconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - mIconLabel->setFixedSize(mIconSize, mIconSize); mIconLabel->setContentsMargins(0, 0, 0, 0); mButtonBox = new QDialogButtonBox; @@ -848,7 +849,7 @@ void MessageBoxPrivate::setupLayout() } QHBoxLayout *titleLayout = new QHBoxLayout; - titleLayout->setContentsMargins(6,0,4,0); + titleLayout->setContentsMargins(6,0,0,0); if(!mTitleIcon->pixmap()->isNull()){ titleLayout->addWidget(mTitleIcon, Qt::AlignLeft | Qt::AlignVCenter); titleLayout->addSpacing(5); @@ -1406,43 +1407,95 @@ bool MessageBoxHelper::show(Qt::WindowFlags windowFlags, Qt::WindowModality wind } } } + + if (windowModality == Qt::WindowModal && mMessageBox->parentWidget() != p) { + ///QDialog center in parent + mMessageBox->setParent(p, Qt::Sheet); + } + else if(mMessageBox->parentWidget() != p){ + ///QDialog center in parent + mMessageBox->setParent(p, Qt::Dialog); + } } } - + else{ + if(windowModality == Qt::WindowModal && mMessageBox->windowFlags() != Qt::Sheet) + mMessageBox->setWindowFlag(Qt::Sheet); + else if(mMessageBox->windowFlags() != Qt::Dialog) + mMessageBox->setWindowFlag(Qt::Dialog); + } mMessageBox->setuplayout(); - if (parent && !mMessageBox->isVisible()) { - mMessageBox->move(QPoint((parent->width() - mMessageBox->width()) / 2, (parent->height() - mMessageBox->height()) / 2) - + QPoint(parent->x(), parent->y())); - } +/* + if (!mMessageBox->isVisible()) { + if(parent){ - QString platform = QGuiApplication::platformName(); - if(platform.startsWith(QLatin1String("wayland"),Qt::CaseInsensitive)) - { - kdk::UkuiStyleHelper::self()->removeHeader(mMessageBox); - } else { - MotifWmHints hints; - hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; - hints.functions = MWM_FUNC_ALL; - hints.decorations = MWM_DECOR_BORDER; - XAtomHelper::getInstance()->setWindowMotifHint(mMessageBox->winId(), hints); + QWidget *p = mMessageBox->find(parent->winId()); + int x = (p->width() - mMessageBox->width()) > 0 ? (p->width() - mMessageBox->width()) / 2 : 0; + int y = (p->height() - mMessageBox->height()) > 0 ? (p->height() - mMessageBox->height()) / 2 : 0; + QPoint gloabP = QPoint(x, y) + p->mapToGlobal(p->pos()); + qDebug() << "gloabP...." << gloabP; + QPoint point = p->mapFromGlobal(gloabP); + qDebug() << "point....." << point; + if (windowModality == Qt::WindowModal) { + qDebug() << "WindowModal............"; + mMessageBox->setParent(p, Qt::Sheet); + } + else{ + qDebug() << "Dialog............"; + mMessageBox->setParent(p, Qt::Dialog); + } + +// mMessageBox->move(point); + qDebug() << "mMessageBox parent......" << p << p->geometry() << p->mapToGlobal(p->pos()); + qDebug() << "mMessageBox ....." << mMessageBox << mMessageBox->geometry(); + + } + else{ + int number = QApplication::desktop()->screenNumber(QCursor::pos()); + if(number<0){ + number=0; + } + QSize size = QApplication::screens().at(number)->availableGeometry().size(); +// qDebug() << "availableGeometry......" << size << QApplication::screens().at(number)->availableSize(); + mMessageBox->move(QPoint((size.width() - mMessageBox->width()) / 2, (size.height() - mMessageBox->height()) / 2)); + + } + + + +// if (QWidget *p = mMessageBox->find(parent->winId())) { +// qDebug() << "isvisible....." << mMessageBox->isVisible(); +// qDebug() << "p geometry1231233333......" << p << p->geometry() << p->mapToGlobal(QPoint(0,0)); +// qDebug() << "parent geometry1231233333......" << parent << parent->geometry() << parent->mapToGlobal(QPoint(0,0)); + +// mMessageBox->move(QPoint((p->width() - mMessageBox->width()) / 2, (p->height() - mMessageBox->height()) / 2) +// + p->mapToGlobal(QPoint(0,0))); + +// mMessageBox->move(QPoint((parent->width() - mMessageBox->width()) / 2, (parent->height() - mMessageBox->height()) / 2) +// + QPoint(parent->x(), parent->y())); +// qDebug() << "parent11111111............" << mMessageBox->geometry() << parent->geometry() << p->geometry(); +// } } +*/ + MotifWmHints hints; + hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; + hints.functions = MWM_FUNC_ALL; + hints.decorations = MWM_DECOR_BORDER; + XAtomHelper::getInstance()->setWindowMotifHint(mMessageBox->winId(), hints); foreach (QAbstractButton *ab, mMessageBox->buttons()) { if (QPushButton *pb = qobject_cast(ab)) { if (pb->isDefault()) { pb->setProperty("isImportant", true); mMessageBox->setDefaultButton(pb); + } else { + pb->setProperty("isImportant", false); } } } mMessageBox->show(); - - Q_UNUSED(parent); - Q_UNUSED(windowFlags); - Q_UNUSED(windowModality); - return true; } diff --git a/ukui-qml-style-helper/KyIcon.cpp b/ukui-qml-style-helper/KyIcon.cpp index c55ef2c..490b838 100644 --- a/ukui-qml-style-helper/KyIcon.cpp +++ b/ukui-qml-style-helper/KyIcon.cpp @@ -31,9 +31,11 @@ KyIcon::KyIcon(QQuickPaintedItem *parent) emit sunkenChanged(); emit onChanged(); emit icontypeChanged(); + emit iconNameChanged(); update(); }); } + connect(this, &KyIcon::iconNameChanged, this, &KyIcon::updateItem); connect(this, &KyIcon::hoverChanged, this, &KyIcon::updateItem); connect(this, &KyIcon::selectedChanged, this, &KyIcon::updateItem); connect(this, &KyIcon::hasFocusChanged, this, &KyIcon::updateItem); @@ -42,6 +44,7 @@ KyIcon::KyIcon(QQuickPaintedItem *parent) connect(this, &KyIcon::onChanged, this, &KyIcon::updateItem); connect(this, &KyIcon::icontypeChanged, this, &KyIcon::updateItem); + } @@ -52,13 +55,15 @@ void KyIcon::setIcon(const QIcon &icon) void KyIcon::setIconName(const QString &iconName) { - if(!QIcon::hasThemeIcon(iconName)) + m_iconName = iconName; + if(!QIcon::hasThemeIcon(m_iconName)) { m_icon = QIcon(); - qWarning() << "未找到名为 " << iconName << " 的图标!"; + qWarning() << "未找到名为 " << m_iconName << " 的图标!"; return; } - m_icon = QIcon::fromTheme(iconName); + m_icon = QIcon::fromTheme(m_iconName); + emit iconNameChanged(); } void KyIcon::paint(QPainter *painter) diff --git a/ukui-qml-style-helper/KyIcon.h b/ukui-qml-style-helper/KyIcon.h index 836bca0..1ec2f7e 100644 --- a/ukui-qml-style-helper/KyIcon.h +++ b/ukui-qml-style-helper/KyIcon.h @@ -9,7 +9,7 @@ class QStyle; class KyIcon : public QQuickPaintedItem { Q_OBJECT - Q_PROPERTY(QString iconName WRITE setIconName) + Q_PROPERTY(QString iconName READ iconName WRITE setIconName NOTIFY iconNameChanged) Q_PROPERTY(QIcon icon READ icon WRITE setIcon) Q_PROPERTY( bool hover READ hover WRITE setHover NOTIFY hoverChanged) Q_PROPERTY( bool selected READ selected WRITE setSelected NOTIFY selectedChanged) @@ -25,7 +25,7 @@ public: QIcon icon() { return m_icon; } void setIcon(const QIcon &icon); - + QString iconName(){ return m_iconName; } void setIconName(const QString &iconName); bool hover() const { return m_hover; } @@ -72,6 +72,7 @@ Q_SIGNALS: void sunkenChanged(); void onChanged(); void icontypeChanged(); + void iconNameChanged(); protected: bool m_hover; @@ -84,6 +85,7 @@ protected: private: QIcon m_icon; + QString m_iconName; }; diff --git a/ukui-qml-style-helper/kyquickstyleitem.cpp b/ukui-qml-style-helper/kyquickstyleitem.cpp index 911a70a..171eda6 100644 --- a/ukui-qml-style-helper/kyquickstyleitem.cpp +++ b/ukui-qml-style-helper/kyquickstyleitem.cpp @@ -1475,16 +1475,18 @@ void KyQuickStyleItem::paint(QPainter *painter) switch (m_itemType) { case Button:{ QWidget wid; - if(m_buttonType=="MaxButton" || m_buttonType=="MinButton" ){ + if(m_buttonType == "MaxButton" || m_buttonType == "MinButton") { wid.setProperty("isWindowButton", QVariant(0x01)); } - if(m_buttonType=="CloseButton"){ + if(m_buttonType == "CloseButton") { wid.setProperty("isWindowButton", QVariant(0x02)); } - if(m_buttonType=="blueButton"){ - wid.setProperty("isImportant",true); + if(m_buttonType == "blueButton") { + wid.setProperty("isImportant", true); + } + if(m_roundButton == "RoundButton") { + wid.setProperty("isRoundButton", true); } - KyQuickStyleItem::style()->drawControl(QStyle::CE_PushButton, m_styleoption, painter,&wid); } break; diff --git a/ukui-qml-style-helper/kyquickstyleitem.h b/ukui-qml-style-helper/kyquickstyleitem.h index 0b120bd..e3cd77f 100644 --- a/ukui-qml-style-helper/kyquickstyleitem.h +++ b/ukui-qml-style-helper/kyquickstyleitem.h @@ -66,6 +66,7 @@ class KyQuickStyleItem: public QQuickItem Q_PROPERTY( int bottomPadding READ bottomPadding NOTIFY bottomPaddingChanged) Q_PROPERTY( QString buttonType READ buttonType WRITE setbuttonType NOTIFY buttonTypeChanged) + Q_PROPERTY( QString roundButton READ roundButton WRITE setroundButton NOTIFY roundButtonChanged) Q_PROPERTY( QQuickItem *control READ control WRITE setControl NOTIFY controlChanged) @@ -199,6 +200,12 @@ public: emit buttonTypeChanged(); } + QString roundButton() const { return m_roundButton;} + void setroundButton(QString roundButton) { + m_roundButton = roundButton ; + emit roundButtonChanged(); + } + public Q_SLOTS: int pixelMetric(const QString&); QVariant styleHint(const QString&); @@ -248,6 +255,7 @@ Q_SIGNALS: void bottomPaddingChanged(); void buttonTypeChanged(); + void roundButtonChanged(); protected: bool event(QEvent *) override; @@ -305,6 +313,7 @@ protected: static QStyle *s_style; QString m_buttonType; + QString m_roundButton; }; #endif // KYQUICKSTYLEITEM_H diff --git a/ukui-qml-style-helper/kystylehelper.cpp b/ukui-qml-style-helper/kystylehelper.cpp index a623e3d..f6ff8d9 100644 --- a/ukui-qml-style-helper/kystylehelper.cpp +++ b/ukui-qml-style-helper/kystylehelper.cpp @@ -11,7 +11,7 @@ KyStyleHelper::KyStyleHelper(QQuickItem *parent) if (QGSettings::isSchemaInstalled("org.ukui.style")) { QGSettings* styleSettings = new QGSettings("org.ukui.style", QByteArray(), this); connect(styleSettings, &QGSettings::changed, this, [&](const QString &key){ - if (key == "styleName") { + if (key == "styleName" || key == "themeColor") { emit paletteChanged(); emit qcolorChanged(); } diff --git a/ukui-qqc2-style/org.ukui.style/RoundButton.qml b/ukui-qqc2-style/org.ukui.style/RoundButton.qml new file mode 100644 index 0000000..bf1be77 --- /dev/null +++ b/ukui-qqc2-style/org.ukui.style/RoundButton.qml @@ -0,0 +1,43 @@ + +import QtQuick 2.6 +import QtQuick.Templates 2.5 as T +import org.ukui.qqc2style.private 1.0 as StylePrivate + +T.RoundButton { + id: controlRoot + palette: StylePrivate.StyleHelper.palette + + /* The value type of buttonType are "CloseButton","MaxButton","MinButton","blueButton","Default". */ + StylePrivate.StyleHelper.buttonType: "Default" + + + implicitWidth: background.implicitWidth + implicitHeight: background.implicitHeight + + hoverEnabled: true //Qt.styleHints.useHoverEffects TODO: how to make this work in 5.7? + + contentItem: Item {} + + background: StylePrivate.StyleItem { + id: styleitem + anchors.fill: parent + buttonType: controlRoot.StylePrivate.StyleHelper.buttonType + control: controlRoot + elementType: "button" + roundButton:"RoundButton" + sunken: controlRoot.pressed || (controlRoot.checkable && controlRoot.checked) + raised: !(controlRoot.pressed || (controlRoot.checkable && controlRoot.checked)) + hover: controlRoot.hovered + text: controlRoot.text + hasFocus: controlRoot.activeFocus + activeControl: controlRoot.isDefault ? "default" : "f" + properties: { + "icon": controlRoot.icon && controlRoot.display !== T.AbstractButton.TextOnly ? (controlRoot.icon.name || controlRoot.icon.source) : "", + "iconWidth": controlRoot.icon && controlRoot.icon.width ? controlRoot.icon.width : 0, + "iconHeight": controlRoot.icon && controlRoot.icon.height ? controlRoot.icon.height : 0, + "flat": controlRoot.flat + } + } +} + + diff --git a/ukui-styles/proxy-style/proxy-style-plugin.cpp b/ukui-styles/proxy-style/proxy-style-plugin.cpp index 3d1a9b3..e830f59 100644 --- a/ukui-styles/proxy-style/proxy-style-plugin.cpp +++ b/ukui-styles/proxy-style/proxy-style-plugin.cpp @@ -47,8 +47,9 @@ ProxyStylePlugin::ProxyStylePlugin() if (UKUIStyleSettings::isSchemaInstalled("org.ukui.style")) { auto settings = UKUIStyleSettings::globalInstance(); connect(settings, &UKUIStyleSettings::changed, this, [=](const QString &key) { - if (key == "styleName" || key == "widgetThemeName" || key == "themeColor") { - if (blackList().contains(qAppName())) + if (key == "styleName" || key == "widgetThemeName" || key == "themeColor" || + key == "style-name" || key == "widget-theme-name" || key == "theme-color") { + if (blackList().contains(qAppName()) || qAppName() == "kylin-software-center.py") return; //We should not swich a application theme which use internal style. diff --git a/ukui-styles/qt5-style-ukui/kabstract-style-parameters.cpp b/ukui-styles/qt5-style-ukui/kabstract-style-parameters.cpp index f9c3b67..ab131c8 100644 --- a/ukui-styles/qt5-style-ukui/kabstract-style-parameters.cpp +++ b/ukui-styles/qt5-style-ukui/kabstract-style-parameters.cpp @@ -216,7 +216,7 @@ KDefaultStyleParameters::KDefaultStyleParameters(QObject *parent, bool isDark) : { radius = 6; - ColoseButtonColor = QColor(243, 34, 45); + ColoseButtonColor = QColor(204, 18, 34); initPalette(isDark); @@ -251,7 +251,7 @@ void KDefaultStyleParameters::initPalette(bool isDark) brightText_dis(0, 0, 0), buttonText_at(38, 38, 38), buttonText_iat(38, 38, 38), - buttonText_dis(179, 179, 179), + buttonText_dis(0, 0, 0, 255 * 0.3), base_at(255, 255, 255), base_iat(245, 245, 245), base_dis(237, 237, 237), @@ -320,7 +320,7 @@ void KDefaultStyleParameters::initPalette(bool isDark) brightText_dis.setRgb(255, 255, 255); buttonText_at.setRgb(217, 217, 217); buttonText_iat.setRgb(217, 217, 217); - buttonText_dis.setRgb(76, 76, 79); + buttonText_dis.setRgb(255, 255, 255, 255 * 0.3); base_at.setRgb(29, 29, 29); base_iat.setRgb(28, 28, 28); base_dis.setRgb(36, 36, 36); @@ -520,13 +520,9 @@ void KDefaultStyleParameters::initPushButtonParameters(bool isDark, const QStyle if (isWindowColoseButton) { QColor ColoseButton = ColoseButtonColor; - if (isDark) { - hoverBrush = QBrush(mixColor(ColoseButton, mix, 0.2)); - clickBrush = QBrush(mixColor(ColoseButton, mix, 0.05)); - } else { - hoverBrush = QBrush(mixColor(ColoseButton, mix, 0.05)); - clickBrush = QBrush(mixColor(ColoseButton, mix, 0.2)); - } + hoverBrush = QBrush(QColor(243, 34, 45)); + clickBrush = QBrush(ColoseButton); + focusPen = QPen(QBrush(mixColor(ColoseButton, mix, 0.2)), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); } else if (isWindowButton && useTransparentButtonList().contains(qAppName())) { @@ -654,13 +650,9 @@ void KDefaultStyleParameters::initToolButtonParameters(bool isDark, const QStyle if (isWindowColoseButton) { QColor ColoseButton = ColoseButtonColor; - if (isDark) { - hoverBrush = QBrush(mixColor(ColoseButton, mix, 0.2)); - clickBrush = QBrush(mixColor(ColoseButton, mix, 0.05)); - } else { - hoverBrush = QBrush(mixColor(ColoseButton, mix, 0.05)); - clickBrush = QBrush(mixColor(ColoseButton, mix, 0.2)); - } + hoverBrush = QBrush(QColor(243, 34, 45)); + clickBrush = QBrush(ColoseButton); + focusPen = QPen(QBrush(mixColor(ColoseButton, mix, 0.2)), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); } else if (isWindowButton && useTransparentButtonList().contains(qAppName())) { @@ -1710,7 +1702,7 @@ void KDefaultStyleParameters::initMenuParameters(bool isDark, const QStyleOption if (qobject_cast(widget)) { QPainter pixmapPainter(&framePixmap); pixmapPainter.setPen(Qt::NoPen); - pixmapPainter.setBrush(option->palette.color(QPalette::Active, QPalette::Base).lighter(300)); + pixmapPainter.setBrush(option->palette.color(QPalette::Active, QPalette::Base).lighter(180)); pixmapPainter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); pixmapPainter.drawRoundedRect(option->rect, frameradius, frameradius); } else { @@ -2061,7 +2053,7 @@ KFashionStyleParameters::KFashionStyleParameters(QObject *parent, bool isDark) : { radius = 6; - ColoseButtonColor = QColor("#F86458"); + ColoseButtonColor = QColor(198, 42, 63); initPalette(isDark); } @@ -2095,7 +2087,7 @@ void KFashionStyleParameters::initPalette(bool isDark) brightText_dis(0, 0, 0), buttonText_at(38, 38, 38), buttonText_iat(38, 38, 38), - buttonText_dis(179, 179, 179), + buttonText_dis(0, 0, 0, 255 * 0.3), base_at(255, 255, 255), base_iat(245, 245, 245), base_dis(237, 237, 237), @@ -2164,7 +2156,7 @@ void KFashionStyleParameters::initPalette(bool isDark) brightText_dis.setRgb(255, 255, 255); buttonText_at.setRgb(217, 217, 217); buttonText_iat.setRgb(217, 217, 217); - buttonText_dis.setRgb(76, 76, 79); + buttonText_dis.setRgb(255, 255, 255, 255 * 0.3); base_at.setRgb(29, 29, 29); base_iat.setRgb(28, 28, 28); base_dis.setRgb(36, 36, 36); @@ -2372,23 +2364,22 @@ void KFashionStyleParameters::initPushButtonParameters(bool isDark, const QStyle if (isWindowColoseButton) { QColor ColoseButton = ColoseButtonColor; - //hover if (isDark) { - startColor = mixColor(ColoseButton, QColor(Qt::white), 0.2); - endColor = mixColor(ColoseButton, QColor(Qt::black), 0.05); + startColor = QColor(242, 116, 133); + endColor = QColor(221, 44, 68); } else { - startColor = mixColor(ColoseButton, QColor(Qt::white), 0.05); - endColor = mixColor(ColoseButton, QColor(Qt::black), 0.2); + startColor = QColor(242, 82, 117); + endColor = QColor(221, 44, 68); } linearGradient.setColorAt(0, startColor); linearGradient.setColorAt(1, endColor); hoverBrush = QBrush(linearGradient); //click - clickBrush = QBrush(mixColor(ColoseButton, mix, 0.1)); + clickBrush = QBrush(ColoseButton); //focus - focusPen = QPen(QBrush(mixColor(ColoseButton, mix, 0.2)), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + focusPen = QPen(QBrush(ColoseButton), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); } else if (isWindowButton && useTransparentButtonList().contains(qAppName())) { if (isDark) { @@ -2553,24 +2544,22 @@ void KFashionStyleParameters::initToolButtonParameters(bool isDark, const QStyle if (isWindowColoseButton) { QColor ColoseButton = ColoseButtonColor; - - //hover - if (isDark) { - startColor = mixColor(ColoseButton, QColor(Qt::white), 0.2); - endColor = mixColor(ColoseButton, QColor(Qt::black), 0.05); + if (isDark) { + startColor = QColor(242, 116, 133); + endColor = QColor(221, 44, 68); } else { - startColor = mixColor(ColoseButton, QColor(Qt::white), 0.05); - endColor = mixColor(ColoseButton, QColor(Qt::black), 0.2); + startColor = QColor(242, 82, 117); + endColor = QColor(221, 44, 68); } linearGradient.setColorAt(0, startColor); linearGradient.setColorAt(1, endColor); hoverBrush = QBrush(linearGradient); //click - clickBrush = QBrush(mixColor(ColoseButton, mix, 0.1)); + clickBrush = QBrush(ColoseButton); //focus - focusPen = QPen(QBrush(mixColor(ColoseButton, mix, 0.2)), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + focusPen = QPen(QBrush(ColoseButton), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); } else if (isWindowButton && useTransparentButtonList().contains(qAppName())) { if (isDark) { @@ -2766,10 +2755,31 @@ void KFashionStyleParameters::initSpinBoxParameters(bool isDark, const QStyleOpt defaultPen.setWidth(0); //hover state - hoverBrush = defaultBrush; hoverPen = defaultPen; if(isHorizonLayout) hoverPen.setWidth(2); + {//hoverBrush + QColor startColor; + QColor endColor; + QColor mix = option->palette.color(QPalette::Active, QPalette::BrightText); + QLinearGradient linearGradient; + linearGradient.setStart(option->rect.topLeft()); + linearGradient.setFinalStop(option->rect.bottomLeft()); + if (isDark) { + startColor = option->palette.color(QPalette::Active, QPalette::Midlight); + endColor = option->palette.color(QPalette::Disabled, QPalette::NoRole); + startColor.setAlphaF(0.5); + endColor.setAlphaF(0.5); + } else { + startColor = option->palette.color(QPalette::Active, QPalette::Midlight); + endColor = mixColor(startColor, mix, 0.1); + startColor.setAlphaF(0.5); + endColor.setAlphaF(0.5); + } + linearGradient.setColorAt(0, startColor); + linearGradient.setColorAt(1, endColor); + hoverBrush = QBrush(linearGradient); + } //focus state focusBrush = option->palette.brush(QPalette::Active, QPalette::Base); @@ -3782,7 +3792,7 @@ void KFashionStyleParameters::initMenuParameters(bool isDark, const QStyleOption QPainter pixmapPainter(&framePixmap); pixmapPainter.setPen(Qt::NoPen); - pixmapPainter.setBrush(option->palette.color(QPalette::Active, QPalette::Base).lighter(300)); + pixmapPainter.setBrush(option->palette.color(QPalette::Active, QPalette::Base).lighter(180)); pixmapPainter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); pixmapPainter.drawPath(drawRectPath); pixmapPainter.end(); diff --git a/ukui-styles/qt5-style-ukui/kabstract-style-parameters.h b/ukui-styles/qt5-style-ukui/kabstract-style-parameters.h index 4e7a560..6108cc7 100644 --- a/ukui-styles/qt5-style-ukui/kabstract-style-parameters.h +++ b/ukui-styles/qt5-style-ukui/kabstract-style-parameters.h @@ -80,7 +80,7 @@ public: int ToolButton_DefaultWidth = 60; int IconButton_DefaultWidth = 36; int IconButton_DefaultWidth_origin = 36; - QColor ColoseButtonColor = QColor(243, 34, 45); + QColor ColoseButtonColor; // menu int Menu_MarginHeight = 4 + 8; @@ -114,6 +114,7 @@ public: int Slider_Length_origin = 20; int Slider_GrooveLength = 4; int Slider_GrooveLength_origin = 4; + int Slider_Margin = 2; // radiobutton int ExclusiveIndicator_Width = 16; @@ -142,6 +143,7 @@ public: int ComboBox_DefaultMenuItemHeight = 36; int ComboBox_DefaultMenuItemHeight_original = 36; int ComboBox_FrameWidth = 2; + int ComboBox_VMargin = 1; // spinbox int SpinBox_DefaultWidth = 160; diff --git a/ukui-styles/qt5-style-ukui/qt5-ukui-style.cpp b/ukui-styles/qt5-style-ukui/qt5-ukui-style.cpp index 8d61ccd..9304a2a 100644 --- a/ukui-styles/qt5-style-ukui/qt5-ukui-style.cpp +++ b/ukui-styles/qt5-style-ukui/qt5-ukui-style.cpp @@ -268,9 +268,6 @@ int Qt5UKUIStyle::styleHint(QStyle::StyleHint hint, const QStyleOption *option, } return m_is_tablet_mode; - case SH_Button_FocusPolicy: - return Qt::TabFocus; - default: break; } @@ -465,7 +462,8 @@ void Qt5UKUIStyle::polish(QWidget *widget) if (qobject_cast(widget)) { //FIXME: unpolish, extensiable. - m_tab_animation_helper->registerWidget(widget); + if (qAppName() != "ukui-sidebar") + m_tab_animation_helper->registerWidget(widget); } if (qobject_cast(widget)) { @@ -478,7 +476,8 @@ void Qt5UKUIStyle::polish(QWidget *widget) if (auto v = qobject_cast(widget)) { v->viewport()->setAttribute(Qt::WA_Hover); - v->setAttribute(Qt::WA_InputMethodEnabled); + //QCompleter BUG113969 +// v->setAttribute(Qt::WA_InputMethodEnabled); } if(qobject_cast(widget)) @@ -750,7 +749,7 @@ QPixmap Qt5UKUIStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &p // return QPixmap::fromImage(im); - //set same color to text when set icon mode disable + //Fix me:set same color to text when set icon mode disable.But it has error in color icons. QColor bg = option->palette.color(QPalette::Disabled, QPalette::WindowText); bg.setAlphaF(0.5); QPainter p(&target); @@ -1930,6 +1929,14 @@ void Qt5UKUIStyle::drawPrimitive(QStyle::PrimitiveElement element, const QStyleO painter->setBrush(button_Hover(option)); painter->drawRoundedRect(option->rect, iconMode_Radius, iconMode_Radius); } + else if (vi->backgroundBrush.style() != Qt::NoBrush) { + QPointF oldBO = painter->brushOrigin(); + painter->setBrushOrigin(vi->rect.topLeft()); + painter->setBrush(vi->backgroundBrush); + painter->drawRoundedRect(vi->rect, iconMode_Radius, iconMode_Radius); + painter->setBrushOrigin(oldBO); + } + painter->restore(); } } else { @@ -1941,6 +1948,7 @@ void Qt5UKUIStyle::drawPrimitive(QStyle::PrimitiveElement element, const QStyleO } painter->save(); + painter->setRenderHint(QPainter::Antialiasing, true); painter->setPen(Qt::NoPen); if (!enable) { painter->setBrush(disableBrush); @@ -2096,28 +2104,55 @@ void Qt5UKUIStyle::drawComplexControl(QStyle::ComplexControl control, const QSty if (slider->subControls & SC_SliderGroove) { if (horizontal) { groove.setHeight(sp->Slider_GrooveLength); + groove.setWidth(groove.width() - 2 * sp->Slider_Margin); } else { groove.setWidth(sp->Slider_GrooveLength); + groove.setHeight(groove.height() - 2 * sp->Slider_Margin); } - groove.moveCenter(option->rect.center()); + groove.moveTo((option->rect.width() - groove.width()) / 2, (option->rect.height() - groove.height()) /2); +// groove.moveCenter(option->rect.center()); QBrush sBrush, gBrush; QRect sRect, gRect; if (horizontal) { if (slider->upsideDown) { - sRect.setRect(handle.center().x(), groove.y(), groove.width() - handle.center().x(), groove.height()); - gRect.setRect(groove.x(), groove.y(), handle.center().x(), groove.height()); + sRect.setLeft(handle.center().x()); + sRect.setTop(groove.top()); + sRect.setRight(groove.right() - 1); + sRect.setBottom(groove.bottom()); + gRect.setLeft(groove.left() + 1); + gRect.setTop(groove.top()); + gRect.setRight(handle.center().x()); + gRect.setBottom(groove.bottom()); } else { - sRect.setRect(groove.x(), groove.y(), handle.center().x(), groove.height()); - gRect.setRect(handle.center().x(), groove.y(), groove.width() - handle.center().x(), groove.height()); + gRect.setLeft(handle.center().x()); + gRect.setTop(groove.top()); + gRect.setRight(groove.right() - 1); + gRect.setBottom(groove.bottom()); + sRect.setLeft(groove.left() + 1); + sRect.setTop(groove.top()); + sRect.setRight(handle.center().x()); + sRect.setBottom(groove.bottom()); } } else { if (slider->upsideDown) { - sRect.setRect(groove.x(), handle.center().y(), groove.width(), groove.height() - handle.center().y()); - gRect.setRect(groove.x(), groove.y(), groove.width(), handle.center().y()); + gRect.setLeft(groove.left()); + gRect.setTop(groove.top() + 1); + gRect.setRight(groove.right()); + gRect.setBottom(handle.center().y()); + sRect.setLeft(groove.left()); + sRect.setTop(handle.center().y()); + sRect.setRight(groove.right()); + sRect.setBottom(groove.bottom() - 1); } else { - sRect.setRect(groove.x(), groove.y(), groove.width(), groove.center().y()); - gRect.setRect(groove.x(), handle.center().y(), groove.width(), groove.height() - handle.center().y()); + sRect.setLeft(groove.left()); + sRect.setTop(groove.top() + 1); + sRect.setRight(groove.right()); + sRect.setBottom(handle.center().y()); + gRect.setLeft(groove.left()); + gRect.setTop(handle.center().y()); + gRect.setRight(groove.right()); + gRect.setBottom(groove.bottom() - 1); } } @@ -2157,6 +2192,7 @@ void Qt5UKUIStyle::drawComplexControl(QStyle::ComplexControl control, const QSty while (v <= slider->maximum) { int pos = sliderPositionFromValue(slider->minimum, slider->maximum, v, proxy()->pixelMetric(PM_SliderSpaceAvailable, option, widget), slider->upsideDown) + len / 2; + pos = pos + sp->Slider_Margin; if (horizontal) { if (slider->tickPosition & QSlider::TicksAbove) painter->drawLine(pos, handle.top() - thickSpace, pos, handle.top() - thickSpace + tick); @@ -2178,6 +2214,11 @@ void Qt5UKUIStyle::drawComplexControl(QStyle::ComplexControl control, const QSty //we need to reinit our brush because it has QGradient without use option rect QStyleOptionSlider handleOption = *slider; handleOption.rect = handle; + if(horizontal) + handle.setY((option->rect.height() - handle.height()) / 2); + else + handle.setX((option->rect.width() - handle.width()) / 2); + sp->initSliderParameters(isUseDarkPalette(), &handleOption, widget); QBrush hBrush; @@ -3392,7 +3433,6 @@ void Qt5UKUIStyle::drawControl(QStyle::ControlElement element, const QStyleOptio } painter->save(); - painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); if (verticalTabs) { int newX, newY, newRot; if (tab->shape == QTabBar::RoundedEast || tab->shape == QTabBar::TriangularEast) { @@ -3411,15 +3451,18 @@ void Qt5UKUIStyle::drawControl(QStyle::ControlElement element, const QStyleOptio } if (!tab->icon.isNull()) { + painter->save(); + painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); QIcon::Mode mode = (tab->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled; QPixmap pixmap = tab->icon.pixmap(widget ? widget->window()->windowHandle() : 0, tab->iconSize, mode, (tab->state & State_Selected) ? QIcon::On : QIcon::Off); pixmap = proxy()->generatedIconPixmap(mode, pixmap, option); QPixmap drawPixmap = HighLightEffect::ordinaryGeneratePixmap(pixmap, option, widget); painter->drawPixmap(iconRect.x(), iconRect.y(), drawPixmap); + painter->restore(); } - proxy()->drawItemText(painter, textRect, alignment, tab->palette, tab->state & State_Enabled, tab->text, QPalette::WindowText); + proxy()->drawItemText(painter, textRect, alignment, tab->palette, tab->state & State_Enabled, tab->text, QPalette::ButtonText); painter->restore(); //draw separate line @@ -3643,7 +3686,7 @@ void Qt5UKUIStyle::drawControl(QStyle::ControlElement element, const QStyleOptio //if it's comobobox popup, set combobox popup size rect if (isComboBox) { int MenuItem_HMargin = proxy()->pixelMetric(PM_MenuVMargin, option, widget); - drawRect.adjust(MenuItem_HMargin, 0, -MenuItem_HMargin, 0); + drawRect.adjust(MenuItem_HMargin, sp->ComboBox_VMargin, -MenuItem_HMargin, -1 * sp->ComboBox_VMargin); } if (enable && (selected | sunken)) { @@ -4211,6 +4254,7 @@ void Qt5UKUIStyle::drawControl(QStyle::ControlElement element, const QStyleOptio case CE_ShapedFrame: if (const QStyleOptionFrame *f = qstyleoption_cast(option)) { + painter->save(); int frameShape = f->frameShape; int frameShadow = QFrame::Plain; if (f->state & QStyle::State_Sunken) { @@ -4235,12 +4279,14 @@ void Qt5UKUIStyle::drawControl(QStyle::ControlElement element, const QStyleOptio } if (frameShadow == QFrame::Plain) { QPen oldPen = painter->pen(); - painter->setPen(QPen(QBrush(f->palette.color(QPalette::Active, QPalette::Window)), lw)); + painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); + painter->setPen(QPen(QBrush(f->palette.color(QPalette::Active, QPalette::NoRole)), lw)); painter->drawLine(p1, p2); painter->setPen(oldPen); } else { qDrawShadeLine(painter, p1, p2, f->palette, frameShadow == QFrame::Sunken, lw, mlw); } + painter->restore(); break; } case QFrame::WinPanel: @@ -4250,6 +4296,7 @@ void Qt5UKUIStyle::drawControl(QStyle::ControlElement element, const QStyleOptio Style::drawControl(element, option, painter, widget); } } + painter->restore(); break; default: return Style::drawControl(element, option, painter, widget); @@ -4290,9 +4337,9 @@ int Qt5UKUIStyle::pixelMetric(QStyle::PixelMetric metric, const QStyleOption *op { if (const QStyleOptionSlider *sl = qstyleoption_cast(option)) { if (sl->orientation == Qt::Horizontal) - return sl->rect.width() - proxy()->pixelMetric(PM_SliderLength, option, widget); + return sl->rect.width() - proxy()->pixelMetric(PM_SliderLength, option, widget) - 2 * sp->Slider_Margin; else - return sl->rect.height() - proxy()->pixelMetric(PM_SliderLength, option, widget); + return sl->rect.height() - proxy()->pixelMetric(PM_SliderLength, option, widget)- 2 * sp->Slider_Margin; } else { return 0; } @@ -4512,9 +4559,9 @@ QRect Qt5UKUIStyle::subControlRect(QStyle::ComplexControl control, const QStyleO int sliderPos = sliderPositionFromValue(slider->minimum, slider->maximum, slider->sliderPosition, proxy()->pixelMetric(PM_SliderSpaceAvailable, option, widget), slider->upsideDown); if (horizontal) { - handleRect.moveLeft(sliderPos); + handleRect.moveLeft(sliderPos + sp->Slider_Margin); } else { - handleRect.moveTop((sliderPos)); + handleRect.moveTop((sliderPos + sp->Slider_Margin)); } return visualRect(slider->direction, slider->rect, handleRect); } @@ -5260,7 +5307,8 @@ QSize Qt5UKUIStyle::sizeFromContents(ContentsType ct, const QStyleOption *option newSize.setWidth(qMax(w + sp->MenuItem_MarginWidth, sp->MenuItem_DefaultWidght)); - newSize.setHeight(qMax(newSize.height() + sp->MenuItem_MarginHeight * 2, sp->MenuItem_DefaultHeight)); + newSize.setHeight(qMax(newSize.height() + sp->MenuItem_MarginHeight * 2, + sp->MenuItem_DefaultHeight + (isComboBox ? (2 * sp->ComboBox_VMargin) : 0))); if (widget) { @@ -5507,18 +5555,10 @@ QSize Qt5UKUIStyle::sizeFromContents(ContentsType ct, const QStyleOption *option if (const QStyleOptionSlider *slider = qstyleoption_cast(option)) { const bool horizontal(slider->orientation == Qt::Horizontal); if (horizontal) { - newSize.setWidth(newSize.height() * sp->m_scaleRatio2_1); - if (slider->tickPosition & QSlider::TicksAbove) - newSize.setHeight(newSize.height() - 3); - if (slider->tickPosition & QSlider::TicksBelow) - newSize.setHeight(newSize.height() - 3); + newSize.setHeight(newSize.height() + 2 * sp->Slider_Margin); newSize.setWidth(qMax(newSize.width(), sp->Slider_DefaultLength)); } else { - newSize.setWidth(newSize.width() * sp->m_scaleRatio2_1); - if (slider->tickPosition & QSlider::TicksAbove) - newSize.setWidth(newSize.width() - 3); - if (slider->tickPosition & QSlider::TicksBelow) - newSize.setWidth(newSize.width() - 3); + newSize.setWidth(newSize.width() + 2 * sp->Slider_Margin); newSize.setHeight(qMax(newSize.height(), sp->Slider_DefaultLength)); } return newSize; diff --git a/ukui-styles/qt5-style-ukui/view-helper.cpp b/ukui-styles/qt5-style-ukui/view-helper.cpp index 5e03e4a..734361e 100644 --- a/ukui-styles/qt5-style-ukui/view-helper.cpp +++ b/ukui-styles/qt5-style-ukui/view-helper.cpp @@ -1,5 +1,6 @@ #include "qt5-ukui-style.h" - +#include +#include static QSizeF viewItemTextLayout(QTextLayout &textLayout, int lineWidth, int maxHeight = -1, int *lastVisibleLine = nullptr) @@ -340,6 +341,18 @@ QSize Qt5UKUIStyle::viewItemSize(const QStyleOptionViewItem *option, int role) c case Qt::DecorationRole: { if (option->features & QStyleOptionViewItem::HasDecoration) { + if(widget){ + if(qobject_cast(widget)){ + QSize size = qobject_cast(widget)->iconSize(); + return QSize(qMax(option->decorationSize.width(), size.width()), + qMax(option->decorationSize.height(), size.height())); + } + if(qobject_cast(widget)){ + QSize size = qobject_cast(widget)->iconSize(); + return QSize(qMax(option->decorationSize.width(), size.width()), + qMax(option->decorationSize.height(), size.height())); + } + } return option->decorationSize; } break;