New upstream version 4.0.0.0

This commit is contained in:
xibowen 2023-03-24 16:47:15 +08:00
parent ca8cd9f37f
commit f9bfc7b891
30 changed files with 970 additions and 328 deletions

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* Authors: Yue Lan <lanyue@kylinos.cn>
*
*/
#include "platform-theme-fontdata.h"
#include <QDebug>
#undef signals
#undef slots
#undef emit
#include <gio/gio.h>
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<QString, QString> PlatformThemeFontData::getAllFontInformation()
{
QMap<QString, QString> fontMap;
QList<FontInformation> 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;
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* Authors: Yue Lan <lanyue@kylinos.cn>
*
*/
#ifndef PLATFORMTHEMEFONTDATA_H
#define PLATFORMTHEMEFONTDATA_H
#include <QObject>
#include <QFont>
#include <fontconfig/fontconfig.h>
#include <freetype2/ft2build.h>
#include <freetype2/freetype/freetype.h>
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<QString, QString> getAllFontInformation();
bool chooseFontFile(QString path);
};
#endif // PLATFORMTHEMEFONTDATA_H

View File

@ -50,6 +50,7 @@
#include "widget/messagebox/message-box.h" #include "widget/messagebox/message-box.h"
#include "widget/filedialog/kyfiledialog.h" #include "widget/filedialog/kyfiledialog.h"
#include "widget/filedialog/debug.h" #include "widget/filedialog/debug.h"
#include "platform-theme-fontdata.h"
#if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON) #if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON)
static bool isDBusTrayAvailable() { static bool isDBusTrayAvailable() {
@ -65,6 +66,69 @@ static bool isDBusTrayAvailable() {
} }
#endif #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<QApplication *>(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<QString, QString> 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<QApplication *>(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) Qt5UKUIPlatformTheme::Qt5UKUIPlatformTheme(const QStringList &args)
{ {
//FIXME: //FIXME:
@ -95,55 +159,16 @@ Qt5UKUIPlatformTheme::Qt5UKUIPlatformTheme(const QStringList &args)
QApplication::setFont(m_system_font); QApplication::setFont(m_system_font);
} }
connect(settings, &QGSettings::changed, this, [=](const QString &key){ if (app->applicationName().toLower().contains(QLatin1String("kwin"))) {
if (key == "iconThemeName") { QDBusConnection::sessionBus().connect(QString(),
QString icontheme = settings->get("icon-theme-name").toString(); QStringLiteral("/UKUIPlatformTheme"),
QStringLiteral("org.ukui.UKUIPlatformTheme"),
QStringLiteral("refreshFonts"),
this,
SLOT(slotChangeStyle(QString)));
}
QIcon::setThemeName(icontheme); connect(settings, &QGSettings::changed, this, &Qt5UKUIPlatformTheme::slotChangeStyle);
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<QApplication *>(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<QApplication *>(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);
}
}
});
} }
// // add qqc2 style // // add qqc2 style
@ -239,11 +264,7 @@ bool Qt5UKUIPlatformTheme::usePlatformNativeDialog(DialogType type) const
{ {
switch (type) { switch (type) {
case QPlatformTheme::FileDialog: case QPlatformTheme::FileDialog:
#ifdef UseNativeFileDialog
return true; return true;
#else
return false;
#endif
case QPlatformTheme::FontDialog: case QPlatformTheme::FontDialog:
case QPlatformTheme::ColorDialog: case QPlatformTheme::ColorDialog:
return false; return false;
@ -262,11 +283,7 @@ QPlatformDialogHelper *Qt5UKUIPlatformTheme::createPlatformDialogHelper(DialogTy
{ {
switch (type) { switch (type) {
case QPlatformTheme::FileDialog: case QPlatformTheme::FileDialog:
#ifdef UseNativeFileDialog
return new KyFileDialogHelper; return new KyFileDialogHelper;
#else
return QPlatformTheme::createPlatformDialogHelper(type);
#endif
case QPlatformTheme::FontDialog: case QPlatformTheme::FontDialog:
case QPlatformTheme::ColorDialog: case QPlatformTheme::ColorDialog:
return QPlatformTheme::createPlatformDialogHelper(type); return QPlatformTheme::createPlatformDialogHelper(type);
@ -302,4 +319,5 @@ QPlatformSystemTrayIcon *Qt5UKUIPlatformTheme::createPlatformSystemTrayIcon() co
return new QDBusTrayIcon(); return new QDBusTrayIcon();
return nullptr; return nullptr;
} }
#endif #endif

View File

@ -86,6 +86,9 @@ public:
QPlatformSystemTrayIcon *createPlatformSystemTrayIcon() const override; QPlatformSystemTrayIcon *createPlatformSystemTrayIcon() const override;
#endif #endif
public Q_SLOTS:
void slotChangeStyle(const QString& key);
private: private:
QFont m_system_font; QFont m_system_font;
QFont m_fixed_font; QFont m_fixed_font;

View File

@ -15,8 +15,8 @@ TARGET = qt5-ukui-platformtheme
TEMPLATE = lib TEMPLATE = lib
CONFIG += plugin CONFIG += plugin
CONFIG += c++11 link_pkgconfig lrelease CONFIG += c++11 link_pkgconfig lrelease
PKGCONFIG += gsettings-qt Qt5XdgIconLoader peony kysdk-waylandhelper PKGCONFIG += gsettings-qt Qt5XdgIconLoader peony fontconfig freetype2
LIBS += -lX11 LIBS += -lX11 -lfontconfig -lfreetype
include(../libqt5-ukui-style/libqt5-ukui-style.pri) include(../libqt5-ukui-style/libqt5-ukui-style.pri)
@ -45,11 +45,13 @@ include(widget/widget.pri)
SOURCES += \ SOURCES += \
qt5-ukui-platform-theme.cpp \ qt5-ukui-platform-theme.cpp \
platform-theme-fontdata.cpp \
main.cpp main.cpp
HEADERS += \ HEADERS += \
qt5-ukui-platform-theme.h \ qt5-ukui-platform-theme.h \
qt5-ukui-platformtheme_global.h qt5-ukui-platformtheme_global.h \
platform-theme-fontdata.h
TRANSLATIONS += \ TRANSLATIONS += \
$$PWD/translations/qt5-ukui-platformtheme_zh_CN.ts \ $$PWD/translations/qt5-ukui-platformtheme_zh_CN.ts \

View File

@ -2,10 +2,6 @@
#define PDEBUG_H #define PDEBUG_H
#include <QDebug> #include <QDebug>
//#ifndef UseNativeFileDialog
//#define UseNativeFileDialog
//#endif
#define SERVICE "com.kylin.statusmanager.interface" #define SERVICE "com.kylin.statusmanager.interface"
#define PATH "/" #define PATH "/"
#define INTERFACE "com.kylin.statusmanager.interface" #define INTERFACE "com.kylin.statusmanager.interface"

View File

@ -1,6 +1,4 @@
#include "debug.h" #include "debug.h"
#ifdef UseNativeFileDialog
#include "kyfiledialog.h" #include "kyfiledialog.h"
#include <QDebug> #include <QDebug>
#include "ui_kyfiledialog.h" #include "ui_kyfiledialog.h"
@ -31,6 +29,9 @@
#include <qwindow.h> #include <qwindow.h>
#include <QScreen> #include <QScreen>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QPainterPath>
#include <QDBusInterface>
#include <QDBusMessage>
#include <qpa/qplatformdialoghelper.h> #include <qpa/qplatformdialoghelper.h>
#include "xatom-helper.h" #include "xatom-helper.h"
#include <peony-qt/file-utils.h> #include <peony-qt/file-utils.h>
@ -68,11 +69,18 @@ KyNativeFileDialog::KyNativeFileDialog(QWidget *parent)
mKyFileDialogUi = new Ui_KyFileDialog; mKyFileDialogUi = new Ui_KyFileDialog;
setStyle(nullptr); // setStyle(nullptr);
// m_fileSystemModel = new QFileSystemModel(); // 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); mKyFileDialogUi->setupUi(this);
d_ptr.get()->m_container = mKyFileDialogUi->m_container; 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){ connect(getCurrentPage(), &Peony::DirectoryViewContainer::updateWindowLocationRequest, this, [=](const QString &uri, bool addToHistory, bool forceUpdate){
pDebug << "page updateWindowLocationRequest.....uri:" << uri << getCurrentUri() << forceUpdate; pDebug << "page updateWindowLocationRequest.....uri:" << uri << getCurrentUri() << forceUpdate;
if(uri == "")
return;
QString s = uri; QString s = uri;
QString s1 = s.endsWith("/") ? s.remove(s.length() - 1, 1) : s; QString s1 = s.endsWith("/") ? s.remove(s.length() - 1, 1) : s;
QString s2 = getCurrentUri(); QString s2 = getCurrentUri();
@ -283,6 +293,7 @@ KyNativeFileDialog::KyNativeFileDialog(QWidget *parent)
refreshContainerSort(); refreshContainerSort();
updateMaximizeState(); updateMaximizeState();
onSwitchView(); onSwitchView();
isTableModel();
m_model = new QStringListModel(); m_model = new QStringListModel();
m_completer = new QCompleter(mKyFileDialogUi->m_fileNameEdit); m_completer = new QCompleter(mKyFileDialogUi->m_fileNameEdit);
@ -303,6 +314,7 @@ KyNativeFileDialog::KyNativeFileDialog(QWidget *parent)
KyNativeFileDialog::~KyNativeFileDialog() KyNativeFileDialog::~KyNativeFileDialog()
{ {
pDebug << "~~~~~~~~KyNativeFileDialog";
} }
@ -332,7 +344,10 @@ Peony::FMWindowIface *KyNativeFileDialog::create(const QStringList &uris)
const QStringList KyNativeFileDialog::getCurrentSelections() const QStringList KyNativeFileDialog::getCurrentSelections()
{ {
return containerView()->getSelections(); if(containerView())
return containerView()->getSelections();
else
return QStringList();
} }
const QStringList KyNativeFileDialog::getCurrentSelectionsList() const QStringList KyNativeFileDialog::getCurrentSelectionsList()
@ -346,7 +361,9 @@ const QStringList KyNativeFileDialog::getCurrentSelectionsList()
const QStringList KyNativeFileDialog::getCurrentAllFileUris() const QStringList KyNativeFileDialog::getCurrentAllFileUris()
{ {
return containerView()->getAllFileUris(); if(containerView())
return containerView()->getAllFileUris();
return QStringList();
} }
const QList<std::shared_ptr<Peony::FileInfo>> KyNativeFileDialog::getCurrentSelectionFileInfos() const QList<std::shared_ptr<Peony::FileInfo>> KyNativeFileDialog::getCurrentSelectionFileInfos()
{ {
@ -365,8 +382,10 @@ void KyNativeFileDialog::setCurrentSelections(QStringList selections)
foreach (QString str, selections) { foreach (QString str, selections) {
list.append(Peony::FileUtils::urlEncode(str)); list.append(Peony::FileUtils::urlEncode(str));
} }
containerView()->setSelections(list); if(containerView()){
pDebug << "get setCurrentSelections....:" << containerView()->getSelections(); containerView()->setSelections(list);
pDebug << "get setCurrentSelections....:" << containerView()->getSelections();
}
} }
Qt::SortOrder KyNativeFileDialog::getCurrentSortOrder() Qt::SortOrder KyNativeFileDialog::getCurrentSortOrder()
@ -441,7 +460,8 @@ void KyNativeFileDialog::forceStopLoading()
if (Peony::ClipboardUtils::isClipboardHasFiles()) if (Peony::ClipboardUtils::isClipboardHasFiles())
{ {
Peony::ClipboardUtils::clearClipboard(); Peony::ClipboardUtils::clearClipboard();
containerView()->repaintView(); if(containerView())
containerView()->repaintView();
} }
} }
@ -474,7 +494,8 @@ void KyNativeFileDialog::setCurrentSelectionUris(const QStringList &uris)
if (Peony::ClipboardUtils::isClipboardHasFiles()) if (Peony::ClipboardUtils::isClipboardHasFiles())
{ {
Peony::ClipboardUtils::clearClipboard(); Peony::ClipboardUtils::clearClipboard();
containerView()->repaintView(); if(containerView())
containerView()->repaintView();
} }
} }
@ -490,12 +511,14 @@ void KyNativeFileDialog::setCurrentSortColumn (int sortColumn)
void KyNativeFileDialog::editUri(const QString &uri) void KyNativeFileDialog::editUri(const QString &uri)
{ {
containerView()->editUri(uri); if(containerView())
containerView()->editUri(uri);
} }
void KyNativeFileDialog::editUris(const QStringList &uris) void KyNativeFileDialog::editUris(const QStringList &uris)
{ {
containerView()->editUris(uris); if(containerView())
containerView()->editUris(uris);
} }
bool KyNativeFileDialog::getFilterWorking() bool KyNativeFileDialog::getFilterWorking()
@ -578,10 +601,15 @@ QUrl KyNativeFileDialog::directoryUrl() const
void KyNativeFileDialog::goToUri(const QString &uri, bool addToHistory, bool forceUpdate) void KyNativeFileDialog::goToUri(const QString &uri, bool addToHistory, bool forceUpdate)
{ {
pDebug << "goToUri....,,,,:" << uri << getCurrentUri(); 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())) if(isInitialGoToUriNum || (m_fileDialogHelper != nullptr && m_fileDialogHelper->isShow()))
{ {
isInitialGoToUriNum = false; isInitialGoToUriNum = false;
getCurrentPage()->stopLoading();
if(uri.startsWith("search:///search_uris=")) if(uri.startsWith("search:///search_uris="))
getCurrentPage()->goToUri(uri, addToHistory, forceUpdate); getCurrentPage()->goToUri(uri, addToHistory, forceUpdate);
else else
@ -778,7 +806,7 @@ void KyNativeFileDialog::selectNameFilterByIndex(int index)
pDebug << "selectNameFilterByIndex00000000000"; pDebug << "selectNameFilterByIndex00000000000";
if (/*d->acceptMode == QFileDialog::AcceptSave &&*/ !newNameFilters.isEmpty() && (d->fileMode != QFileDialog::DirectoryOnly && d->fileMode != QFileDialog::Directory)) { if (/*d->acceptMode == QFileDialog::AcceptSave &&*/ !newNameFilters.isEmpty() && (d->fileMode != QFileDialog::DirectoryOnly && d->fileMode != QFileDialog::Directory)) {
QMimeDatabase db; QMimeDatabase db;
QString text = mKyFileDialogUi->m_fileNameEdit->text(); QString text = copyEditText();//mKyFileDialogUi->m_fileNameEdit->text();
pDebug << "selectNameFilterByIndex text...." << text; pDebug << "selectNameFilterByIndex text...." << text;
pDebug << "selectNameFilterByIndex newNameFilters...." << newNameFilters; pDebug << "selectNameFilterByIndex newNameFilters...." << newNameFilters;
QStringList list = text.split("."); QStringList list = text.split(".");
@ -868,6 +896,7 @@ void KyNativeFileDialog::setAcceptMode(QFileDialog::AcceptMode mode)
mKyFileDialogUi->m_newFolderButton->show(); mKyFileDialogUi->m_newFolderButton->show();
mKyFileDialogUi->m_acceptButton->setText(tr("Save")); mKyFileDialogUi->m_acceptButton->setText(tr("Save"));
mKyFileDialogUi->m_rejectButton->setText(tr("Cancel")); mKyFileDialogUi->m_rejectButton->setText(tr("Cancel"));
mKyFileDialogUi->m_acceptButton->setDefault(true);
connect(mKyFileDialogUi->m_fileNameEdit, &QLineEdit::textChanged, this, &KyNativeFileDialog::onCurrentInputNameChanged); connect(mKyFileDialogUi->m_fileNameEdit, &QLineEdit::textChanged, this, &KyNativeFileDialog::onCurrentInputNameChanged);
connect(mKyFileDialogUi->m_newFolderButton, &QPushButton::clicked, this, &KyNativeFileDialog::onNewFolder); connect(mKyFileDialogUi->m_newFolderButton, &QPushButton::clicked, this, &KyNativeFileDialog::onNewFolder);
} }
@ -918,21 +947,23 @@ QFileDialog::FileMode KyNativeFileDialog::fileMode()
void KyNativeFileDialog::setViewMode(ViewMode mode) void KyNativeFileDialog::setViewMode(ViewMode mode)
{ {
pDebug << "setViewMode...." << mode << containerView()->viewId(); if(containerView()){
if(mode == ViewMode::List && containerView()->viewId() != "List View") pDebug << "setViewMode...." << mode << containerView()->viewId();
{ if(mode == ViewMode::List && containerView()->viewId() != "List View")
this->getCurrentPage()->switchViewType("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 KyNativeFileDialog::ViewMode KyNativeFileDialog::viewMode() const
{ {
// this->getCurrentPage()->switchViewType("List View"); // this->getCurrentPage()->switchViewType("List View");
if(containerView()->viewId() == "List View") if(containerView() && containerView()->viewId() == "List View")
return ViewMode::List; return ViewMode::List;
return ViewMode::Icon; return ViewMode::Icon;
} }
@ -1000,7 +1031,8 @@ QFileDialog::Options KyNativeFileDialog::options() const
void KyNativeFileDialog::setCurrentInputName(const QString &name) void KyNativeFileDialog::setCurrentInputName(const QString &name)
{ {
pDebug << "setCurrentInputName.........:" << name; pDebug << "setCurrentInputName.........:" << name;
mKyFileDialogUi->m_fileNameEdit->setText(name); m_copyEditText = name;
// mKyFileDialogUi->m_fileNameEdit->setText(name);
QMimeDatabase db; QMimeDatabase db;
const QString &suffix = db.suffixForFileName(name); const QString &suffix = db.suffixForFileName(name);
if (suffix.isEmpty()) { if (suffix.isEmpty()) {
@ -1017,13 +1049,29 @@ void KyNativeFileDialog::onAcceptButtonClicked()
return; return;
} }
pDebug << "onAcceptButtonClicked:" << d->acceptMode << d->fileMode; 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<QString> 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<QString> sFiles = selectedFiles(); QList<QString> sFiles = selectedFiles();
pDebug << "sfiles..........:" << sFiles; pDebug << "onAcceptButtonClicked sfiles..........:" << sFiles;
// pDebug << "getSelections........:" << containerView()->getSelections(); // pDebug << "getSelections........:" << containerView()->getSelections();
// pDebug << "uri:" << Peony::FileUtils::getTargetUri(getCurrentUri()); // pDebug << "uri:" << Peony::FileUtils::getTargetUri(getCurrentUri());
// pDebug << "uri1111111111:" << Peony::FileUtils::getParentUri(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 (d->acceptMode == QFileDialog::AcceptSave)
{ {
if(!doSave(sFiles)) if(!doSave(sFiles))
@ -1084,35 +1120,34 @@ void KyNativeFileDialog::onAcceptButtonClicked()
bool KyNativeFileDialog::saveMessageBox(QString name) bool KyNativeFileDialog::saveMessageBox(QString name)
{ {
QMessageBox *msg = new QMessageBox(QMessageBox::Warning, tr("Warning"), name + tr("exist, are you sure replace?"), QMessageBox::Ok | QMessageBox::No); if(QMessageBox::warning(this, tr("Warning"), name + " " + tr("exist, are you sure replace?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
foreach (QAbstractButton* item, msg->buttons()) { {
if(msg->standardButton(item) == QMessageBox::Ok){ return true;
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;
});
}
} }
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) bool KyNativeFileDialog::doSave(QStringList sFiles)
{ {
Q_D(KyNativeFileDialog); Q_D(KyNativeFileDialog);
QString file_name = mKyFileDialogUi->m_fileNameEdit->text(); QString file_name = copyEditText();
bool suffixCheck = false; bool suffixCheck = false;
QStringList nameFilters = d->nameFilters; QStringList nameFilters = d->nameFilters;
for (QString nameFilterList : nameFilters) { for (QString nameFilterList : nameFilters) {
@ -1164,13 +1199,20 @@ bool KyNativeFileDialog::doSave(QStringList sFiles)
oldName.append('.' + suffix); oldName.append('.' + suffix);
setCurrentInputName(oldName); setCurrentInputName(oldName);
pDebug << "path///:" << directory().path() + "/" + oldName; pDebug << "path///:" << directory().path() + "/" + oldName;
QFile file(directory().path() + "/" + oldName); if(checkSaveFileExsits(directory().path() + "/" + oldName)){
if(file.exists()) if(!saveMessageBox(oldName))
return false;
break; break;
}
if(filter == newNameFilters[newNameFilters.length() - 1]) if(filter == newNameFilters[newNameFilters.length() - 1])
{ {
QString oldName = file_name; QString oldName = file_name;
oldName.append('.' + mdb.suffixForFileName(newNameFilters[0])); oldName.append('.' + mdb.suffixForFileName(newNameFilters[0]));
if(checkSaveFileExsits(directory().path() + "/" + oldName)){
if(!saveMessageBox(oldName))
return false;
break;
}
setCurrentInputName(oldName); setCurrentInputName(oldName);
return true; return true;
} }
@ -1179,11 +1221,23 @@ bool KyNativeFileDialog::doSave(QStringList sFiles)
} }
else{ else{
file_name.append('.' + m_fileDialogHelper->options()->defaultSuffix()); file_name.append('.' + m_fileDialogHelper->options()->defaultSuffix());
if(checkSaveFileExsits(directory().path() + "/" + file_name)){
if(!saveMessageBox(file_name))
return false;
}
setCurrentInputName(file_name); setCurrentInputName(file_name);
pDebug << "path///:" << directory().path() + "/" + 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; return true;
} }
@ -1223,11 +1277,11 @@ bool KyNativeFileDialog::doOpen(QStringList sFiles)
{ {
Q_EMIT filesSelected(selectedUrls()); Q_EMIT filesSelected(selectedUrls());
} }
else if(mKyFileDialogUi->m_fileNameEdit->text() != "") else if(copyEditText() != "")
{ {
QList<QUrl> urlList; QList<QUrl> urlList;
pDebug << "directory path:" << directory().path() << directoryUrl().path(); 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); Q_EMIT filesSelected(urlList);
} }
else else
@ -1235,7 +1289,7 @@ bool KyNativeFileDialog::doOpen(QStringList sFiles)
} }
else if(d->fileMode == QFileDialog::DirectoryOnly || d->fileMode == QFileDialog::Directory) 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]))) if(sFiles.isEmpty() || (!sFiles.isEmpty() && !isDir(sFiles[0])))
{ {
@ -1263,7 +1317,8 @@ bool KyNativeFileDialog::doOpen(QStringList sFiles)
{ {
urls << QUrl::fromLocalFile(Peony::FileUtils::urlDecode(uri)); urls << QUrl::fromLocalFile(Peony::FileUtils::urlDecode(uri));
} }
pDebug << "select uri....:" << containerView()->getSelections(); if(containerView())
pDebug << "select uri....:" << containerView()->getSelections();
Q_EMIT filesSelected(urls); Q_EMIT filesSelected(urls);
} }
@ -1280,8 +1335,14 @@ void KyNativeFileDialog::onRejectButtonClicked()
} }
bool KyNativeFileDialog::isDir(QString path) 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); QFile file(path);
QFileInfo fileInfo(file); QFileInfo fileInfo(file);
pDebug << "isDir path1111:" << path << fileInfo.isDir() << Peony::FileUtils::isFileDirectory(path) << Peony::FileUtils::getFileIsFolder(path);; pDebug << "isDir path1111:" << path << fileInfo.isDir() << Peony::FileUtils::isFileDirectory(path) << Peony::FileUtils::getFileIsFolder(path);;
@ -1339,7 +1400,7 @@ void KyNativeFileDialog::onSwitchView()
void KyNativeFileDialog::updateWindowState() void KyNativeFileDialog::updateWindowState()
{ {
Q_D(KyNativeFileDialog); 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(""); //mKyFileDialogUi->m_fileNameEdit->setText("");
pDebug << "updateWindowState m_searchMode.............." <<m_searchMode << getCurrentUri() << m_isClearSearchKey; pDebug << "updateWindowState m_searchMode.............." <<m_searchMode << getCurrentUri() << m_isClearSearchKey;
@ -1374,7 +1435,7 @@ void KyNativeFileDialog::updateWindowState()
mKyFileDialogUi->m_toParentButton->setEnabled(getCurrentPage()->canCdUp()); mKyFileDialogUi->m_toParentButton->setEnabled(getCurrentPage()->canCdUp());
updateStatusBar(); updateStatusBar();
pDebug << "updateWindowState 44444"; pDebug << "updateWindowState 44444";
lineEditTextChange(mKyFileDialogUi->m_fileNameEdit->text()); lineEditTextChange(copyEditText());
pDebug << "updateWindowState 55555555555555555555" << uri; pDebug << "updateWindowState 55555555555555555555" << uri;
} }
@ -1385,7 +1446,14 @@ QString KyNativeFileDialog::selectName()
QString nameStr = ""; QString nameStr = "";
for(int i = 0; i < selectList.length(); i++) 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 str = Peony::FileUtils::getFileDisplayName(selectList[i]);//Peony::FileUtils::urlDecode(selectList[i]);
QString name = ""; QString name = "";
if(selectList.length() == 1) if(selectList.length() == 1)
@ -1396,6 +1464,16 @@ QString KyNativeFileDialog::selectName()
name += "\"" + str.split("/").last() + "\""; name += "\"" + str.split("/").last() + "\"";
nameStr += name; 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; return nameStr;
} }
@ -1433,12 +1511,15 @@ void KyNativeFileDialog::containerMenuRequest(const QPoint &pos)
void KyNativeFileDialog::delayShow() void KyNativeFileDialog::delayShow()
{ {
Q_D(const KyNativeFileDialog); Q_D(const KyNativeFileDialog);
//QTBUG48248 借鉴kde plasma-integration里用的QTimer
pDebug << "delayShow start...........";
d->m_timer->start(); d->m_timer->start();
} }
void KyNativeFileDialog::discardDelayedShow() void KyNativeFileDialog::discardDelayedShow()
{ {
Q_D(const KyNativeFileDialog); Q_D(const KyNativeFileDialog);
pDebug << "discardDelayedShow stop...........";
d->m_timer->stop(); d->m_timer->stop();
} }
@ -1576,13 +1657,15 @@ void KyNativeFileDialog::updateAcceptButtonState()
{ {
if(d->fileMode != QFileDialog::Directory && d->fileMode != QFileDialog::DirectoryOnly) if(d->fileMode != QFileDialog::Directory && d->fileMode != QFileDialog::DirectoryOnly)
{ {
mKyFileDialogUi->m_acceptButton->setEnabled(!(getCurrentSelectionsList().length() == 0));
return;
bool isSelectFile = false; bool isSelectFile = false;
if(mKyFileDialogUi->m_fileNameEdit->text() == "") if(copyEditText() == "")
mKyFileDialogUi->m_acceptButton->setEnabled(false); 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("\""); QStringList list = text.split("\"");
pDebug << "list234565432............" << list; pDebug << "list234565432............" << list;
for (int i = list.length() - 1; i >= 0; i--) { for (int i = list.length() - 1; i >= 0; i--) {
@ -1638,9 +1721,9 @@ void KyNativeFileDialog::updateAcceptButtonState()
else else
{ {
bool isSelectFile = true; bool isSelectFile = true;
if(mKyFileDialogUi->m_fileNameEdit->text() != "") if(copyEditText() != "")
{ {
QString text = mKyFileDialogUi->m_fileNameEdit->text(); QString text = copyEditText();
QStringList list = text.split("\""); QStringList list = text.split("\"");
pDebug << "list0000............" << list; pDebug << "list0000............" << list;
for (int i = list.length() - 1; i >= 0; i--) { for (int i = list.length() - 1; i >= 0; i--) {
@ -1680,7 +1763,11 @@ void KyNativeFileDialog::updateAcceptButtonState()
} }
else else
{ {
if(mKyFileDialogUi->m_fileNameEdit->text() == "") if(getCurrentSelectionsList().length() != 0){
mKyFileDialogUi->m_acceptButton->setEnabled(true);
return;
}
if(copyEditText() == "")
mKyFileDialogUi->m_acceptButton->setEnabled(false); mKyFileDialogUi->m_acceptButton->setEnabled(false);
else else
mKyFileDialogUi->m_acceptButton->setEnabled(true); mKyFileDialogUi->m_acceptButton->setEnabled(true);
@ -1692,7 +1779,7 @@ void KyNativeFileDialog::updateAcceptButtonState()
void KyNativeFileDialog::onCurrentInputNameChanged() void KyNativeFileDialog::onCurrentInputNameChanged()
{ {
Q_D(KyNativeFileDialog); Q_D(KyNativeFileDialog);
d->currentInputName = mKyFileDialogUi->m_fileNameEdit->text(); d->currentInputName = copyEditText();
updateAcceptButtonState(); updateAcceptButtonState();
} }
@ -1798,6 +1885,7 @@ void KyNativeFileDialog::setSearchMode(bool mode)
void KyNativeFileDialog::lineEditTextChange(QString text) void KyNativeFileDialog::lineEditTextChange(QString text)
{ {
m_copyEditText = text;
if(m_searchMode) if(m_searchMode)
return; return;
QString url; QString url;
@ -1813,13 +1901,24 @@ void KyNativeFileDialog::lineEditTextChange(QString text)
url.remove(url.length() - 1, 1); url.remove(url.length() - 1, 1);
pDebug << "parentPath:" << parentPath; pDebug << "parentPath:" << parentPath;
pDebug << "getCurrentSelections......:" << getCurrentSelectionsList() << text;
if(!text.contains("\"")) if(!text.contains("\""))//输入框中只有1个文件
{ {
if ((parentPath.startsWith("trash://") || parentPath.startsWith("recent://") if ((parentPath.startsWith("trash://") || parentPath.startsWith("recent://")
|| parentPath.startsWith("computer://") || parentPath.startsWith("favorite://") || parentPath.startsWith("computer://") || parentPath.startsWith("favorite://")
|| parentPath.startsWith("filesafe://")) && getCurrentSelections().length() > 0) || 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 targetUri = Peony::FileUtils::getTargetUri(getCurrentSelections()[0]);
QString targetPath = Peony::FileUtils::urlDecode(targetUri); QString targetPath = Peony::FileUtils::urlDecode(targetUri);
pDebug << "getTargetUri uri....." << targetUri; pDebug << "getTargetUri uri....." << targetUri;
@ -1836,8 +1935,16 @@ void KyNativeFileDialog::lineEditTextChange(QString text)
} }
else 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); // 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)){ if(Peony::FileUtils::isFileExsit(parentPath + "/" + text)){
pDebug << "file exists...."; pDebug << "file exists....";
//m_container选择指定文件 //m_container选择指定文件
@ -1845,7 +1952,8 @@ void KyNativeFileDialog::lineEditTextChange(QString text)
selectList.append(parentPath + "/" + text); selectList.append(parentPath + "/" + text);
pDebug << "selectList...1111111" << selectList; pDebug << "selectList...1111111" << selectList;
setCurrentSelections(selectList); setCurrentSelections(selectList);
pDebug << "selectList...22222222222" << containerView()->getSelections(); if(containerView())
pDebug << "selectList...22222222222" << containerView()->getSelections();
updateAcceptButtonState(); updateAcceptButtonState();
return; return;
} }
@ -1865,6 +1973,31 @@ void KyNativeFileDialog::lineEditTextChange(QString text)
|| parentPath.startsWith("computer://") || parentPath.startsWith("favorite://") || parentPath.startsWith("computer://") || parentPath.startsWith("favorite://")
|| parentPath.startsWith("filesafe://"))) || 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; QStringList selectList;
foreach (QString str, getCurrentSelections()) foreach (QString str, getCurrentSelections())
{ {
@ -1892,6 +2025,24 @@ void KyNativeFileDialog::lineEditTextChange(QString text)
} }
pDebug << "listtttt22222222..............:" << list; 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) { foreach (QString str, list) {
if(str.length() > 0 && str[0] == "\"") if(str.length() > 0 && str[0] == "\"")
str = str.remove(0, 1); str = str.remove(0, 1);
@ -2026,14 +2177,16 @@ void KyNativeFileDialog::setShortCuts()
auto maxAction = new QAction(this); auto maxAction = new QAction(this);
maxAction->setShortcut(QKeySequence(Qt::Key_F11)); maxAction->setShortcut(QKeySequence(Qt::Key_F11));
connect(maxAction, &QAction::triggered, this, [=]() { connect(maxAction, &QAction::triggered, this, [=]() {
//showFullScreen has some issue, change to showMaximized, fix #20043 if(!m_istableModel){
mKyFileDialogUi->m_pathbar->cancelEdit(); //showFullScreen has some issue, change to showMaximized, fix #20043
if (!this->isMaximized()) { mKyFileDialogUi->m_pathbar->cancelEdit();
this->showMaximized(); if (!this->isMaximized()) {
} else { this->showMaximized();
this->showNormal(); } else {
this->showNormal();
}
updateMaximizeState();
} }
updateMaximizeState();
}); });
addAction(maxAction); addAction(maxAction);
@ -2192,6 +2345,8 @@ void KyNativeFileDialog::setShortCuts()
void KyNativeFileDialog::initialViewId() void KyNativeFileDialog::initialViewId()
{ {
if(!containerView())
return;
int zoomLevel = containerView()->currentZoomLevel(); int zoomLevel = containerView()->currentZoomLevel();
auto viewId = Peony::DirectoryViewFactoryManager2::getInstance()->getDefaultViewId(zoomLevel, getCurrentUri()); auto viewId = Peony::DirectoryViewFactoryManager2::getInstance()->getDefaultViewId(zoomLevel, getCurrentUri());
@ -2199,6 +2354,37 @@ void KyNativeFileDialog::initialViewId()
beginSwitchView(viewId); 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<bool>());
}
}
void KyNativeFileDialog::updateTableModel(bool tableModel)
{
m_istableModel = tableModel;
mKyFileDialogUi->m_maximizeAndRestore->setVisible(!tableModel);
}
KyFileDialogHelper::KyFileDialogHelper() : QPlatformFileDialogHelper(), mKyFileDialog(new KyNativeFileDialog) KyFileDialogHelper::KyFileDialogHelper() : QPlatformFileDialogHelper(), mKyFileDialog(new KyNativeFileDialog)
{ {
mKyFileDialog->setHelper(this); mKyFileDialog->setHelper(this);
@ -2206,8 +2392,10 @@ KyFileDialogHelper::KyFileDialogHelper() : QPlatformFileDialogHelper(), mKyFileD
pDebug << "KyFileDialogHelper........." << (options() == nullptr); pDebug << "KyFileDialogHelper........." << (options() == nullptr);
connect(mKyFileDialog, &KyNativeFileDialog::currentChanged, this, &KyFileDialogHelper::currentChanged); connect(mKyFileDialog, &KyNativeFileDialog::currentChanged, this, &KyFileDialogHelper::currentChanged);
connect(mKyFileDialog, &KyNativeFileDialog::directoryEntered, this, &KyFileDialogHelper::directoryEntered); connect(mKyFileDialog, &KyNativeFileDialog::directoryEntered, this, &KyFileDialogHelper::directoryEntered);
connect(mKyFileDialog, &KyNativeFileDialog::fileSelected, this, &KyFileDialogHelper::fileSelected); //QFileDialog::accept()里_q_emitUrlSelected会发送fileSelected信号 这里会导致发两次fileSelected的信号
connect(mKyFileDialog, &KyNativeFileDialog::filesSelected, this, &KyFileDialogHelper::filesSelected); // 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, &KyNativeFileDialog::filterSelected, this, &KyFileDialogHelper::filterSelected);
connect(mKyFileDialog, &QDialog::accepted, this, &KyFileDialogHelper::accept); connect(mKyFileDialog, &QDialog::accepted, this, &KyFileDialogHelper::accept);
connect(mKyFileDialog, &QDialog::rejected, this, &KyFileDialogHelper::reject); connect(mKyFileDialog, &QDialog::rejected, this, &KyFileDialogHelper::reject);
@ -2216,11 +2404,18 @@ KyFileDialogHelper::KyFileDialogHelper() : QPlatformFileDialogHelper(), mKyFileD
KyFileDialogHelper::~KyFileDialogHelper() KyFileDialogHelper::~KyFileDialogHelper()
{ {
pDebug << "~~~~~~~~KyFileDialogHelper";
///不可以析构 普通函数里QFileDialog::show不显示和QFiledialog->show()会显示 析构的话BT下载工具打开不显示界面
// if(mKyFileDialog){
// mKyFileDialog->deleteLater();
// mKyFileDialog = nullptr;
// }
} }
void KyFileDialogHelper::exec() void KyFileDialogHelper::exec()
{ {
pDebug << "KyFileDialogHelper::exec..............";
mKyFileDialog->discardDelayedShow(); mKyFileDialog->discardDelayedShow();
mKyFileDialog->exec(); mKyFileDialog->exec();
} }
@ -2249,7 +2444,19 @@ bool KyFileDialogHelper::show(Qt::WindowFlags windowFlags, Qt::WindowModality wi
for(QFileDialog *fd : p->findChildren<QFileDialog *>()){ for(QFileDialog *fd : p->findChildren<QFileDialog *>()){
if(options()->windowTitle() == fd->windowTitle()){ if(options()->windowTitle() == fd->windowTitle()){
pDebug << "filedoalog set parent...." << fd->geometry(); 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<QPushButton*>()) // for(QPushButton *btn : mKyFileDialog->findChildren<QPushButton*>())
// { // {
// if(btn->objectName() == "acceptButton") // if(btn->objectName() == "acceptButton")
@ -2336,6 +2543,10 @@ void KyFileDialogHelper::viewInitialFinished()
if(m_viewInitialFinished) if(m_viewInitialFinished)
return; return;
pDebug << "viewInitialFinished...."; pDebug << "viewInitialFinished....";
QTimer::singleShot(100, this, [this](){
pDebug << "viewport update1111111.......";
mKyFileDialog->mKyFileDialogUi->m_sider->viewport()->update();
});
QTimer::singleShot(500, this, [this](){ 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 << "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())) 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->intiContainerSort();
mKyFileDialog->initialViewId(); mKyFileDialog->initialViewId();
pDebug << "viewport update222222.......";
mKyFileDialog->mKyFileDialogUi->m_sider->viewport()->update();
// mKyFileDialog->refresh();
m_viewInitialFinished = true; m_viewInitialFinished = true;
}); });
} }
@ -2454,7 +2676,7 @@ QList<QUrl> KyFileDialogHelper::selectedFiles() const
{ {
QList<QUrl> urlList = mKyFileDialog->selectedUrls(); QList<QUrl> urlList = mKyFileDialog->selectedUrls();
if((options()->fileMode() == QFileDialogOptions::Directory || options()->fileMode() == QFileDialogOptions::DirectoryOnly) && if((options()->fileMode() == QFileDialogOptions::Directory || options()->fileMode() == QFileDialogOptions::DirectoryOnly) &&
mKyFileDialog->mKyFileDialogUi->m_fileNameEdit->text() == "" && m_viewInitialFinished) mKyFileDialog->copyEditText() == "" && m_viewInitialFinished)
{ {
if (!mKyFileDialog->getCurrentPage()) { if (!mKyFileDialog->getCurrentPage()) {
return QList<QUrl>(); return QList<QUrl>();
@ -2486,8 +2708,8 @@ QList<QUrl> KyFileDialogHelper::selectedFiles() const
QString path = mKyFileDialog->getCurrentUri(); QString path = mKyFileDialog->getCurrentUri();
if(!path.endsWith("/")) if(!path.endsWith("/"))
path += "/"; path += "/";
pDebug << "selected filesss...:" << path + mKyFileDialog->mKyFileDialogUi->m_fileNameEdit->text(); pDebug << "selected filesss...:" << path + mKyFileDialog->copyEditText();
urlList.append(QUrl(path + mKyFileDialog->mKyFileDialogUi->m_fileNameEdit->text())); urlList.append(QUrl(path + mKyFileDialog->copyEditText()));
return urlList; return urlList;
} }
} }
@ -2497,7 +2719,7 @@ QList<QUrl> KyFileDialogHelper::selectedFiles() const
QString path = mKyFileDialog->getCurrentUri(); QString path = mKyFileDialog->getCurrentUri();
if(!path.endsWith("/")) if(!path.endsWith("/"))
path += "/"; path += "/";
path += mKyFileDialog->mKyFileDialogUi->m_fileNameEdit->text(); path += mKyFileDialog->copyEditText();
if(path.startsWith("file:///")) if(path.startsWith("file:///"))
path = path.remove(0,7); path = path.remove(0,7);
pDebug << "save selectedFiles00000..........:" << path; pDebug << "save selectedFiles00000..........:" << path;
@ -2545,5 +2767,3 @@ bool KyFileDialogHelper::isSupportedUrl(const QUrl &url) const
return url.isLocalFile(); return url.isLocalFile();
} }
#endif

View File

@ -1,5 +1,4 @@
#include "debug.h" #include "debug.h"
#ifdef UseNativeFileDialog
#ifndef KYNATIVEFILEDIALOG_H #ifndef KYNATIVEFILEDIALOG_H
#define KYNATIVEFILEDIALOG_H #define KYNATIVEFILEDIALOG_H
#include <QDialog> #include <QDialog>
@ -150,6 +149,11 @@ public:
void initialViewId(); void initialViewId();
void delayShow();
void discardDelayedShow();
QString copyEditText();
Q_SIGNALS: Q_SIGNALS:
void switchViewRequest(const QString &viewId); void switchViewRequest(const QString &viewId);
@ -171,14 +175,13 @@ public Q_SLOTS:
void updateWindowState(); void updateWindowState();
QString selectName(); QString selectName();
void updateStatusBar(); void updateStatusBar();
void delayShow();
void discardDelayedShow();
void onNewFolder(); void onNewFolder();
void setSortType(); void setSortType();
void searchButtonClicked(); void searchButtonClicked();
void setSearchMode(bool mode); void setSearchMode(bool mode);
void lineEditTextChange(QString text); void lineEditTextChange(QString text);
void containerMenuRequest(const QPoint &pos); void containerMenuRequest(const QPoint &pos);
void updateTableModel(bool tableMode);
protected: protected:
void resizeEvent(QResizeEvent *e); void resizeEvent(QResizeEvent *e);
@ -195,6 +198,8 @@ private:
void onCurrentInputNameChanged(); void onCurrentInputNameChanged();
void handleEnterPressed(); void handleEnterPressed();
void updateAcceptButtonState(); void updateAcceptButtonState();
bool checkSaveFileExsits(QString path);
void isTableModel();
private: private:
bool m_searchMode = false; bool m_searchMode = false;
@ -208,6 +213,8 @@ private:
QString m_lastSearchPath; QString m_lastSearchPath;
bool m_isClearSearchKey = false; bool m_isClearSearchKey = false;
QStringListModel *m_model = nullptr; QStringListModel *m_model = nullptr;
QString m_copyEditText;
bool m_istableModel = false;
}; };
@ -264,4 +271,3 @@ private:
#endif // KYNATIVEFILEDIALOG_H #endif // KYNATIVEFILEDIALOG_H
#endif

View File

@ -1,5 +1,4 @@
#include "debug.h" #include "debug.h"
#ifdef UseNativeFileDialog
#include "kyfiledialogprivate.h" #include "kyfiledialogprivate.h"
#include <QFileDialog> #include <QFileDialog>
@ -57,4 +56,3 @@ QStringList KyNativeFileDialogPrivate::typedFiles()
*/ */
return QStringList(); return QStringList();
} }
#endif

View File

@ -1,5 +1,4 @@
#include "debug.h" #include "debug.h"
#ifdef UseNativeFileDialog
#ifndef KYNATIVEFILEDIALOGPRIVATE_H #ifndef KYNATIVEFILEDIALOGPRIVATE_H
#define KYNATIVEFILEDIALOGPRIVATE_H #define KYNATIVEFILEDIALOGPRIVATE_H
@ -29,7 +28,6 @@ private:
}; };
#endif // KYNATIVEFILEDIALOGPRIVATE_H #endif // KYNATIVEFILEDIALOGPRIVATE_H
#endif
/* /*
KyNativeFileDialogPrivate::KyNativeFileDialogPrivate() KyNativeFileDialogPrivate::KyNativeFileDialogPrivate()
{ {

View File

@ -1,6 +1,4 @@
#include "debug.h" #include "debug.h"
#ifdef UseNativeFileDialog
#include "menutoolbutoon.h" #include "menutoolbutoon.h"
#include <QApplication> #include <QApplication>
#include <QDBusInterface> #include <QDBusInterface>
@ -75,4 +73,3 @@ void ToolButtonStyle::drawPrimitive(QStyle::PrimitiveElement element, const QSty
} }
return qApp->style()->drawPrimitive(element, option, painter, widget); return qApp->style()->drawPrimitive(element, option, painter, widget);
} }
#endif

View File

@ -1,5 +1,4 @@
#include "debug.h" #include "debug.h"
#ifdef UseNativeFileDialog
#ifndef MENUTOOLBUTTON_H #ifndef MENUTOOLBUTTON_H
#define 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; void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr) const override;
}; };
#endif // MENUTOOLBUTTON_H #endif // MENUTOOLBUTTON_H
#endif

View File

@ -1,5 +1,4 @@
#include "debug.h" #include "debug.h"
#ifdef UseNativeFileDialog
#include "pathbar.h" #include "pathbar.h"
#include <PeonyPathCompleter> #include <PeonyPathCompleter>
@ -74,4 +73,3 @@ void FileDialogPathBar::updateTableModel(bool isTable)
} }
pDebug << "m_pathBar height1111:" << m_pathBar->height() << this->height(); pDebug << "m_pathBar height1111:" << m_pathBar->height() << this->height();
} }
#endif

View File

@ -1,5 +1,4 @@
#include "debug.h" #include "debug.h"
#ifdef UseNativeFileDialog
#ifndef PATHBAR_H #ifndef PATHBAR_H
#define PATHBAR_H #define PATHBAR_H
@ -28,4 +27,3 @@ private:
Peony::AdvancedLocationBar *m_pathBar = nullptr; Peony::AdvancedLocationBar *m_pathBar = nullptr;
}; };
#endif // PATHBAR_H #endif // PATHBAR_H
#endif

View File

@ -1,6 +1,4 @@
#include "debug.h" #include "debug.h"
#ifdef UseNativeFileDialog
#include "sidebar.h" #include "sidebar.h"
#include <QTimer> #include <QTimer>
#include <PeonySideBarModel> #include <PeonySideBarModel>
@ -77,7 +75,7 @@ FileDialogSideBar::FileDialogSideBar(QWidget *parent) : QTreeView(parent)
header()->setStretchLastSection(false); header()->setStretchLastSection(false);
header()->hide(); header()->hide();
this->verticalScrollBar()->setProperty("drawScrollBarGroove", true); this->verticalScrollBar()->setProperty("drawScrollBarGroove", false);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
this->setFrameStyle(QFrame::NoFrame); this->setFrameStyle(QFrame::NoFrame);
setSortingEnabled(true); setSortingEnabled(true);
@ -453,4 +451,3 @@ void SideBarStyle::drawControl(QStyle::ControlElement element, const QStyleOptio
return qApp->style()->drawControl(element, &opt, painter, widget); return qApp->style()->drawControl(element, &opt, painter, widget);
} }
} }
#endif

View File

@ -1,6 +1,4 @@
#include "debug.h" #include "debug.h"
#ifdef UseNativeFileDialog
#ifndef SIDEBAR_H #ifndef SIDEBAR_H
#define SIDEBAR_H #define SIDEBAR_H
#include <QTreeView> #include <QTreeView>
@ -72,4 +70,3 @@ public:
void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const override; void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const override;
}; };
#endif // SIDEBAR_H #endif // SIDEBAR_H
#endif

View File

@ -1,6 +1,4 @@
#include "debug.h" #include "debug.h"
#ifdef UseNativeFileDialog
#include "ui_kyfiledialog.h" #include "ui_kyfiledialog.h"
#include <QFileDialog> #include <QFileDialog>
#include "kyfiledialog.h" #include "kyfiledialog.h"
@ -61,7 +59,7 @@ void Ui_KyFileDialog::initSortMenu(QDialog *mKyFileDialog)
m_sortButton->setMenu(m_sortMenu); m_sortButton->setMenu(m_sortMenu);
m_sortButton->setPopupMode(QToolButton::InstantPopup); m_sortButton->setPopupMode(QToolButton::InstantPopup);
m_sortButton->setAutoRaise(true); m_sortButton->setAutoRaise(true);
m_sortButton->setFixedWidth(57); m_sortButton->setFixedSize(QSize(57, 40));
m_sortButton->setIconSize(QSize(16, 16)); m_sortButton->setIconSize(QSize(16, 16));
} }
@ -71,7 +69,7 @@ void Ui_KyFileDialog::initModeMenu(QDialog *mKyFileDialog)
m_modeButton = new MenuToolButton(); m_modeButton = new MenuToolButton();
m_modeButton->setPopupMode(QToolButton::InstantPopup); m_modeButton->setPopupMode(QToolButton::InstantPopup);
m_modeButton->setAutoRaise(true); m_modeButton->setAutoRaise(true);
m_modeButton->setFixedWidth(57); m_modeButton->setFixedSize(QSize(57, 40));
m_modeButton->setIconSize(QSize(16, 16)); m_modeButton->setIconSize(QSize(16, 16));
m_modeMenu = new QMenu(m_modeButton); m_modeMenu = new QMenu(m_modeButton);
@ -95,18 +93,14 @@ void Ui_KyFileDialog::initSiderBar(QDialog *mKyFileDialog)
void Ui_KyFileDialog::initHeaderBar(QDialog *mKyFileDialog) void Ui_KyFileDialog::initHeaderBar(QDialog *mKyFileDialog)
{ {
m_hHeaderLayout = new QHBoxLayout(); m_hHeaderLayout = new QHBoxLayout();
m_hHeaderLayout->setContentsMargins(4,5,4,5);
initModeMenu(mKyFileDialog); initModeMenu(mKyFileDialog);
initSortMenu(mKyFileDialog); initSortMenu(mKyFileDialog);
m_hHeaderLayout->setContentsMargins(0,0,0,0); m_hHeaderLayout->setContentsMargins(0,0,8,0);
m_hHeaderLayout->setObjectName(QString::fromUtf8("hboxLayout")); m_hHeaderLayout->setObjectName(QString::fromUtf8("hboxLayout"));
m_backButton = new QToolButton(); m_backButton = new QToolButton();
m_forwardButton = new QToolButton(); m_forwardButton = new QToolButton();
m_toParentButton = 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_pathbarWidget = new FileDialogPathBar();//new Peony::AdvancedLocationBar(mKyFileDialog);//
m_pathbar = m_pathbarWidget->getPathBar(); m_pathbar = m_pathbarWidget->getPathBar();
@ -208,8 +202,7 @@ void Ui_KyFileDialog::setupUi(QDialog *mKyFileDialog)
m_gridLayout = new QGridLayout(mKyFileDialog); m_gridLayout = new QGridLayout(mKyFileDialog);
m_gridLayout->setObjectName(QString::fromUtf8("gridLayout")); m_gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
m_container = new Peony::DirectoryViewContainer(mKyFileDialog); m_container = new Peony::DirectoryViewContainer();
m_container->setObjectName("container");
m_frame = new QFrame(); m_frame = new QFrame();
vboxLayout = new QVBoxLayout(); vboxLayout = new QVBoxLayout();
@ -221,12 +214,13 @@ void Ui_KyFileDialog::setupUi(QDialog *mKyFileDialog)
vboxLayout->addSpacing(8); vboxLayout->addSpacing(8);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout")); vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
vboxLayout->setContentsMargins(0, 0, 8, 0); vboxLayout->setContentsMargins(0, 0, 0, 0);
vboxLayout->addLayout(m_hHeaderLayout); vboxLayout->addLayout(m_hHeaderLayout);
vboxLayout->addSpacing(12); vboxLayout->addSpacing(6);
m_upSeperate = new QFrame(); m_upSeperate = new QFrame(mKyFileDialog);
m_upSeperate->setFrameShape(QFrame::HLine); m_upSeperate->setFrameShape(QFrame::HLine);
m_upSeperate->setFrameShadow(QFrame::Plain);
vboxLayout->addWidget(m_upSeperate); vboxLayout->addWidget(m_upSeperate);
vboxLayout->addSpacing(6); vboxLayout->addSpacing(6);
vboxLayout->addWidget(m_container); vboxLayout->addWidget(m_container);
@ -235,8 +229,9 @@ void Ui_KyFileDialog::setupUi(QDialog *mKyFileDialog)
vboxLayout->addLayout(m_hLineEditLayout); vboxLayout->addLayout(m_hLineEditLayout);
vboxLayout->addSpacing(16); vboxLayout->addSpacing(16);
m_downSeperate = new QFrame(); m_downSeperate = new QFrame(mKyFileDialog);
m_downSeperate->setFrameShape(QFrame::HLine); m_downSeperate->setFrameShape(QFrame::HLine);
m_downSeperate->setFrameShadow(QFrame::Plain);
vboxLayout->addWidget(m_downSeperate); vboxLayout->addWidget(m_downSeperate);
vboxLayout->addSpacing(16); vboxLayout->addSpacing(16);
@ -269,4 +264,3 @@ void Ui_KyFileDialog::setupUi(QDialog *mKyFileDialog)
m_gridLayout->addWidget(m_splitter); m_gridLayout->addWidget(m_splitter);
m_gridLayout->setContentsMargins(0,0,0,0); m_gridLayout->setContentsMargins(0,0,0,0);
} }
#endif

View File

@ -1,6 +1,4 @@
#include "debug.h" #include "debug.h"
#ifdef UseNativeFileDialog
#ifndef UI_KYFILEDIALOG_H #ifndef UI_KYFILEDIALOG_H
#define UI_KYFILEDIALOG_H #define UI_KYFILEDIALOG_H
#include <QApplication> #include <QApplication>
@ -100,4 +98,3 @@ private:
void intiBtnLayout(QDialog *mKyFileDialog); void intiBtnLayout(QDialog *mKyFileDialog);
}; };
#endif // UI_KYFILEDIALOG_H #endif // UI_KYFILEDIALOG_H
#endif

View File

@ -32,8 +32,6 @@
#include <QStyleOption> #include <QStyleOption>
#include <qpa/qplatformdialoghelper.h> #include <qpa/qplatformdialoghelper.h>
#include <QtWidgets/qdialogbuttonbox.h> #include <QtWidgets/qdialogbuttonbox.h>
#include "ukuistylehelper/ukuistylehelper.h"
#include "windowmanager/windowmanager.h"
#include "private/qlabel_p.h" #include "private/qlabel_p.h"
#include "private/qdialog_p.h" #include "private/qdialog_p.h"
@ -208,8 +206,10 @@ QPixmap MessageBox::iconPixmap() const
void MessageBox::setIconPixmap(const QPixmap &pixmap) void MessageBox::setIconPixmap(const QPixmap &pixmap)
{ {
Q_D(MessageBox); Q_D(MessageBox);
if (!pixmap.isNull()) if (!pixmap.isNull()){
d->mIconLabel->setPixmap(pixmap.scaled(d->mIconSize, d->mIconSize)); d->mIconLabel->setAlignment(Qt::AlignVCenter);
d->mIconLabel->setPixmap(pixmap);
}
d->mIcon = QMessageBox::NoIcon; d->mIcon = QMessageBox::NoIcon;
} }
@ -491,11 +491,11 @@ void MessageBox::setWindowModality(Qt::WindowModality windowModality)
{ {
QDialog::setWindowModality(windowModality); QDialog::setWindowModality(windowModality);
if (parentWidget() && windowModality == Qt::WindowModal) { // if (parentWidget() && windowModality == Qt::WindowModal) {
setParent(parentWidget(), Qt::Sheet); // setParent(parentWidget(), Qt::Sheet);
} else { // } else {
setParent(parentWidget(), Qt::Dialog); // setParent(parentWidget(), Qt::Dialog);
} // }
setDefaultButton(d_func()->mDefaultButton); setDefaultButton(d_func()->mDefaultButton);
} }
@ -707,6 +707,7 @@ MessageBoxPrivate::MessageBoxPrivate() : mCheckbox(nullptr), mEscapeButton(nullp
MessageBoxPrivate::~MessageBoxPrivate() MessageBoxPrivate::~MessageBoxPrivate()
{ {
/*
if (nullptr != mLabel) { if (nullptr != mLabel) {
delete mLabel; delete mLabel;
} }
@ -726,6 +727,7 @@ MessageBoxPrivate::~MessageBoxPrivate()
if (nullptr != mDetailButton) { if (nullptr != mDetailButton) {
delete mDetailButton; delete mDetailButton;
} }
*/
} }
void MessageBoxPrivate::init(const QString &title, const QString &text) 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 = new QLabel;
mIconLabel->setObjectName(QLatin1String("ukui_msgbox_icon_label")); mIconLabel->setObjectName(QLatin1String("ukui_msgbox_icon_label"));
mIconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); mIconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
mIconLabel->setFixedSize(mIconSize, mIconSize);
mIconLabel->setContentsMargins(0, 0, 0, 0); mIconLabel->setContentsMargins(0, 0, 0, 0);
mButtonBox = new QDialogButtonBox; mButtonBox = new QDialogButtonBox;
@ -848,7 +849,7 @@ void MessageBoxPrivate::setupLayout()
} }
QHBoxLayout *titleLayout = new QHBoxLayout; QHBoxLayout *titleLayout = new QHBoxLayout;
titleLayout->setContentsMargins(6,0,4,0); titleLayout->setContentsMargins(6,0,0,0);
if(!mTitleIcon->pixmap()->isNull()){ if(!mTitleIcon->pixmap()->isNull()){
titleLayout->addWidget(mTitleIcon, Qt::AlignLeft | Qt::AlignVCenter); titleLayout->addWidget(mTitleIcon, Qt::AlignLeft | Qt::AlignVCenter);
titleLayout->addSpacing(5); 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(); mMessageBox->setuplayout();
if (parent && !mMessageBox->isVisible()) { /*
mMessageBox->move(QPoint((parent->width() - mMessageBox->width()) / 2, (parent->height() - mMessageBox->height()) / 2) if (!mMessageBox->isVisible()) {
+ QPoint(parent->x(), parent->y())); if(parent){
}
QString platform = QGuiApplication::platformName(); QWidget *p = mMessageBox->find(parent->winId());
if(platform.startsWith(QLatin1String("wayland"),Qt::CaseInsensitive)) 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;
kdk::UkuiStyleHelper::self()->removeHeader(mMessageBox); QPoint gloabP = QPoint(x, y) + p->mapToGlobal(p->pos());
} else { qDebug() << "gloabP...." << gloabP;
MotifWmHints hints; QPoint point = p->mapFromGlobal(gloabP);
hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; qDebug() << "point....." << point;
hints.functions = MWM_FUNC_ALL; if (windowModality == Qt::WindowModal) {
hints.decorations = MWM_DECOR_BORDER; qDebug() << "WindowModal............";
XAtomHelper::getInstance()->setWindowMotifHint(mMessageBox->winId(), hints); 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()) { foreach (QAbstractButton *ab, mMessageBox->buttons()) {
if (QPushButton *pb = qobject_cast<QPushButton *>(ab)) { if (QPushButton *pb = qobject_cast<QPushButton *>(ab)) {
if (pb->isDefault()) { if (pb->isDefault()) {
pb->setProperty("isImportant", true); pb->setProperty("isImportant", true);
mMessageBox->setDefaultButton(pb); mMessageBox->setDefaultButton(pb);
} else {
pb->setProperty("isImportant", false);
} }
} }
} }
mMessageBox->show(); mMessageBox->show();
Q_UNUSED(parent);
Q_UNUSED(windowFlags);
Q_UNUSED(windowModality);
return true; return true;
} }

View File

@ -31,9 +31,11 @@ KyIcon::KyIcon(QQuickPaintedItem *parent)
emit sunkenChanged(); emit sunkenChanged();
emit onChanged(); emit onChanged();
emit icontypeChanged(); emit icontypeChanged();
emit iconNameChanged();
update(); update();
}); });
} }
connect(this, &KyIcon::iconNameChanged, this, &KyIcon::updateItem);
connect(this, &KyIcon::hoverChanged, this, &KyIcon::updateItem); connect(this, &KyIcon::hoverChanged, this, &KyIcon::updateItem);
connect(this, &KyIcon::selectedChanged, this, &KyIcon::updateItem); connect(this, &KyIcon::selectedChanged, this, &KyIcon::updateItem);
connect(this, &KyIcon::hasFocusChanged, 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::onChanged, this, &KyIcon::updateItem);
connect(this, &KyIcon::icontypeChanged, 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) void KyIcon::setIconName(const QString &iconName)
{ {
if(!QIcon::hasThemeIcon(iconName)) m_iconName = iconName;
if(!QIcon::hasThemeIcon(m_iconName))
{ {
m_icon = QIcon(); m_icon = QIcon();
qWarning() << "未找到名为 " << iconName << " 的图标!"; qWarning() << "未找到名为 " << m_iconName << " 的图标!";
return; return;
} }
m_icon = QIcon::fromTheme(iconName); m_icon = QIcon::fromTheme(m_iconName);
emit iconNameChanged();
} }
void KyIcon::paint(QPainter *painter) void KyIcon::paint(QPainter *painter)

View File

@ -9,7 +9,7 @@ class QStyle;
class KyIcon : public QQuickPaintedItem class KyIcon : public QQuickPaintedItem
{ {
Q_OBJECT 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(QIcon icon READ icon WRITE setIcon)
Q_PROPERTY( bool hover READ hover WRITE setHover NOTIFY hoverChanged) Q_PROPERTY( bool hover READ hover WRITE setHover NOTIFY hoverChanged)
Q_PROPERTY( bool selected READ selected WRITE setSelected NOTIFY selectedChanged) Q_PROPERTY( bool selected READ selected WRITE setSelected NOTIFY selectedChanged)
@ -25,7 +25,7 @@ public:
QIcon icon() { return m_icon; } QIcon icon() { return m_icon; }
void setIcon(const QIcon &icon); void setIcon(const QIcon &icon);
QString iconName(){ return m_iconName; }
void setIconName(const QString &iconName); void setIconName(const QString &iconName);
bool hover() const { return m_hover; } bool hover() const { return m_hover; }
@ -72,6 +72,7 @@ Q_SIGNALS:
void sunkenChanged(); void sunkenChanged();
void onChanged(); void onChanged();
void icontypeChanged(); void icontypeChanged();
void iconNameChanged();
protected: protected:
bool m_hover; bool m_hover;
@ -84,6 +85,7 @@ protected:
private: private:
QIcon m_icon; QIcon m_icon;
QString m_iconName;
}; };

View File

@ -1475,16 +1475,18 @@ void KyQuickStyleItem::paint(QPainter *painter)
switch (m_itemType) { switch (m_itemType) {
case Button:{ case Button:{
QWidget wid; QWidget wid;
if(m_buttonType=="MaxButton" || m_buttonType=="MinButton" ){ if(m_buttonType == "MaxButton" || m_buttonType == "MinButton") {
wid.setProperty("isWindowButton", QVariant(0x01)); wid.setProperty("isWindowButton", QVariant(0x01));
} }
if(m_buttonType=="CloseButton"){ if(m_buttonType == "CloseButton") {
wid.setProperty("isWindowButton", QVariant(0x02)); wid.setProperty("isWindowButton", QVariant(0x02));
} }
if(m_buttonType=="blueButton"){ if(m_buttonType == "blueButton") {
wid.setProperty("isImportant",true); wid.setProperty("isImportant", true);
}
if(m_roundButton == "RoundButton") {
wid.setProperty("isRoundButton", true);
} }
KyQuickStyleItem::style()->drawControl(QStyle::CE_PushButton, m_styleoption, painter,&wid); KyQuickStyleItem::style()->drawControl(QStyle::CE_PushButton, m_styleoption, painter,&wid);
} }
break; break;

View File

@ -66,6 +66,7 @@ class KyQuickStyleItem: public QQuickItem
Q_PROPERTY( int bottomPadding READ bottomPadding NOTIFY bottomPaddingChanged) Q_PROPERTY( int bottomPadding READ bottomPadding NOTIFY bottomPaddingChanged)
Q_PROPERTY( QString buttonType READ buttonType WRITE setbuttonType NOTIFY buttonTypeChanged) 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) Q_PROPERTY( QQuickItem *control READ control WRITE setControl NOTIFY controlChanged)
@ -199,6 +200,12 @@ public:
emit buttonTypeChanged(); emit buttonTypeChanged();
} }
QString roundButton() const { return m_roundButton;}
void setroundButton(QString roundButton) {
m_roundButton = roundButton ;
emit roundButtonChanged();
}
public Q_SLOTS: public Q_SLOTS:
int pixelMetric(const QString&); int pixelMetric(const QString&);
QVariant styleHint(const QString&); QVariant styleHint(const QString&);
@ -248,6 +255,7 @@ Q_SIGNALS:
void bottomPaddingChanged(); void bottomPaddingChanged();
void buttonTypeChanged(); void buttonTypeChanged();
void roundButtonChanged();
protected: protected:
bool event(QEvent *) override; bool event(QEvent *) override;
@ -305,6 +313,7 @@ protected:
static QStyle *s_style; static QStyle *s_style;
QString m_buttonType; QString m_buttonType;
QString m_roundButton;
}; };
#endif // KYQUICKSTYLEITEM_H #endif // KYQUICKSTYLEITEM_H

View File

@ -11,7 +11,7 @@ KyStyleHelper::KyStyleHelper(QQuickItem *parent)
if (QGSettings::isSchemaInstalled("org.ukui.style")) { if (QGSettings::isSchemaInstalled("org.ukui.style")) {
QGSettings* styleSettings = new QGSettings("org.ukui.style", QByteArray(), this); QGSettings* styleSettings = new QGSettings("org.ukui.style", QByteArray(), this);
connect(styleSettings, &QGSettings::changed, this, [&](const QString &key){ connect(styleSettings, &QGSettings::changed, this, [&](const QString &key){
if (key == "styleName") { if (key == "styleName" || key == "themeColor") {
emit paletteChanged(); emit paletteChanged();
emit qcolorChanged(); emit qcolorChanged();
} }

View File

@ -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
}
}
}

View File

@ -47,8 +47,9 @@ ProxyStylePlugin::ProxyStylePlugin()
if (UKUIStyleSettings::isSchemaInstalled("org.ukui.style")) { if (UKUIStyleSettings::isSchemaInstalled("org.ukui.style")) {
auto settings = UKUIStyleSettings::globalInstance(); auto settings = UKUIStyleSettings::globalInstance();
connect(settings, &UKUIStyleSettings::changed, this, [=](const QString &key) { connect(settings, &UKUIStyleSettings::changed, this, [=](const QString &key) {
if (key == "styleName" || key == "widgetThemeName" || key == "themeColor") { if (key == "styleName" || key == "widgetThemeName" || key == "themeColor" ||
if (blackList().contains(qAppName())) key == "style-name" || key == "widget-theme-name" || key == "theme-color") {
if (blackList().contains(qAppName()) || qAppName() == "kylin-software-center.py")
return; return;
//We should not swich a application theme which use internal style. //We should not swich a application theme which use internal style.

View File

@ -216,7 +216,7 @@ KDefaultStyleParameters::KDefaultStyleParameters(QObject *parent, bool isDark) :
{ {
radius = 6; radius = 6;
ColoseButtonColor = QColor(243, 34, 45); ColoseButtonColor = QColor(204, 18, 34);
initPalette(isDark); initPalette(isDark);
@ -251,7 +251,7 @@ void KDefaultStyleParameters::initPalette(bool isDark)
brightText_dis(0, 0, 0), brightText_dis(0, 0, 0),
buttonText_at(38, 38, 38), buttonText_at(38, 38, 38),
buttonText_iat(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_at(255, 255, 255),
base_iat(245, 245, 245), base_iat(245, 245, 245),
base_dis(237, 237, 237), base_dis(237, 237, 237),
@ -320,7 +320,7 @@ void KDefaultStyleParameters::initPalette(bool isDark)
brightText_dis.setRgb(255, 255, 255); brightText_dis.setRgb(255, 255, 255);
buttonText_at.setRgb(217, 217, 217); buttonText_at.setRgb(217, 217, 217);
buttonText_iat.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_at.setRgb(29, 29, 29);
base_iat.setRgb(28, 28, 28); base_iat.setRgb(28, 28, 28);
base_dis.setRgb(36, 36, 36); base_dis.setRgb(36, 36, 36);
@ -520,13 +520,9 @@ void KDefaultStyleParameters::initPushButtonParameters(bool isDark, const QStyle
if (isWindowColoseButton) { if (isWindowColoseButton) {
QColor ColoseButton = ColoseButtonColor; QColor ColoseButton = ColoseButtonColor;
if (isDark) { hoverBrush = QBrush(QColor(243, 34, 45));
hoverBrush = QBrush(mixColor(ColoseButton, mix, 0.2)); clickBrush = QBrush(ColoseButton);
clickBrush = QBrush(mixColor(ColoseButton, mix, 0.05));
} else {
hoverBrush = QBrush(mixColor(ColoseButton, mix, 0.05));
clickBrush = QBrush(mixColor(ColoseButton, mix, 0.2));
}
focusPen = QPen(QBrush(mixColor(ColoseButton, mix, 0.2)), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); focusPen = QPen(QBrush(mixColor(ColoseButton, mix, 0.2)), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
} else if (isWindowButton && useTransparentButtonList().contains(qAppName())) { } else if (isWindowButton && useTransparentButtonList().contains(qAppName())) {
@ -654,13 +650,9 @@ void KDefaultStyleParameters::initToolButtonParameters(bool isDark, const QStyle
if (isWindowColoseButton) { if (isWindowColoseButton) {
QColor ColoseButton = ColoseButtonColor; QColor ColoseButton = ColoseButtonColor;
if (isDark) { hoverBrush = QBrush(QColor(243, 34, 45));
hoverBrush = QBrush(mixColor(ColoseButton, mix, 0.2)); clickBrush = QBrush(ColoseButton);
clickBrush = QBrush(mixColor(ColoseButton, mix, 0.05));
} else {
hoverBrush = QBrush(mixColor(ColoseButton, mix, 0.05));
clickBrush = QBrush(mixColor(ColoseButton, mix, 0.2));
}
focusPen = QPen(QBrush(mixColor(ColoseButton, mix, 0.2)), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); focusPen = QPen(QBrush(mixColor(ColoseButton, mix, 0.2)), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
} else if (isWindowButton && useTransparentButtonList().contains(qAppName())) { } else if (isWindowButton && useTransparentButtonList().contains(qAppName())) {
@ -1710,7 +1702,7 @@ void KDefaultStyleParameters::initMenuParameters(bool isDark, const QStyleOption
if (qobject_cast<const QFrame*>(widget)) { if (qobject_cast<const QFrame*>(widget)) {
QPainter pixmapPainter(&framePixmap); QPainter pixmapPainter(&framePixmap);
pixmapPainter.setPen(Qt::NoPen); 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.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
pixmapPainter.drawRoundedRect(option->rect, frameradius, frameradius); pixmapPainter.drawRoundedRect(option->rect, frameradius, frameradius);
} else { } else {
@ -2061,7 +2053,7 @@ KFashionStyleParameters::KFashionStyleParameters(QObject *parent, bool isDark) :
{ {
radius = 6; radius = 6;
ColoseButtonColor = QColor("#F86458"); ColoseButtonColor = QColor(198, 42, 63);
initPalette(isDark); initPalette(isDark);
} }
@ -2095,7 +2087,7 @@ void KFashionStyleParameters::initPalette(bool isDark)
brightText_dis(0, 0, 0), brightText_dis(0, 0, 0),
buttonText_at(38, 38, 38), buttonText_at(38, 38, 38),
buttonText_iat(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_at(255, 255, 255),
base_iat(245, 245, 245), base_iat(245, 245, 245),
base_dis(237, 237, 237), base_dis(237, 237, 237),
@ -2164,7 +2156,7 @@ void KFashionStyleParameters::initPalette(bool isDark)
brightText_dis.setRgb(255, 255, 255); brightText_dis.setRgb(255, 255, 255);
buttonText_at.setRgb(217, 217, 217); buttonText_at.setRgb(217, 217, 217);
buttonText_iat.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_at.setRgb(29, 29, 29);
base_iat.setRgb(28, 28, 28); base_iat.setRgb(28, 28, 28);
base_dis.setRgb(36, 36, 36); base_dis.setRgb(36, 36, 36);
@ -2372,23 +2364,22 @@ void KFashionStyleParameters::initPushButtonParameters(bool isDark, const QStyle
if (isWindowColoseButton) { if (isWindowColoseButton) {
QColor ColoseButton = ColoseButtonColor; QColor ColoseButton = ColoseButtonColor;
//hover
if (isDark) { if (isDark) {
startColor = mixColor(ColoseButton, QColor(Qt::white), 0.2); startColor = QColor(242, 116, 133);
endColor = mixColor(ColoseButton, QColor(Qt::black), 0.05); endColor = QColor(221, 44, 68);
} else { } else {
startColor = mixColor(ColoseButton, QColor(Qt::white), 0.05); startColor = QColor(242, 82, 117);
endColor = mixColor(ColoseButton, QColor(Qt::black), 0.2); endColor = QColor(221, 44, 68);
} }
linearGradient.setColorAt(0, startColor); linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor); linearGradient.setColorAt(1, endColor);
hoverBrush = QBrush(linearGradient); hoverBrush = QBrush(linearGradient);
//click //click
clickBrush = QBrush(mixColor(ColoseButton, mix, 0.1)); clickBrush = QBrush(ColoseButton);
//focus //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())) { } else if (isWindowButton && useTransparentButtonList().contains(qAppName())) {
if (isDark) { if (isDark) {
@ -2553,24 +2544,22 @@ void KFashionStyleParameters::initToolButtonParameters(bool isDark, const QStyle
if (isWindowColoseButton) { if (isWindowColoseButton) {
QColor ColoseButton = ColoseButtonColor; QColor ColoseButton = ColoseButtonColor;
if (isDark) {
//hover startColor = QColor(242, 116, 133);
if (isDark) { endColor = QColor(221, 44, 68);
startColor = mixColor(ColoseButton, QColor(Qt::white), 0.2);
endColor = mixColor(ColoseButton, QColor(Qt::black), 0.05);
} else { } else {
startColor = mixColor(ColoseButton, QColor(Qt::white), 0.05); startColor = QColor(242, 82, 117);
endColor = mixColor(ColoseButton, QColor(Qt::black), 0.2); endColor = QColor(221, 44, 68);
} }
linearGradient.setColorAt(0, startColor); linearGradient.setColorAt(0, startColor);
linearGradient.setColorAt(1, endColor); linearGradient.setColorAt(1, endColor);
hoverBrush = QBrush(linearGradient); hoverBrush = QBrush(linearGradient);
//click //click
clickBrush = QBrush(mixColor(ColoseButton, mix, 0.1)); clickBrush = QBrush(ColoseButton);
//focus //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())) { } else if (isWindowButton && useTransparentButtonList().contains(qAppName())) {
if (isDark) { if (isDark) {
@ -2766,10 +2755,31 @@ void KFashionStyleParameters::initSpinBoxParameters(bool isDark, const QStyleOpt
defaultPen.setWidth(0); defaultPen.setWidth(0);
//hover state //hover state
hoverBrush = defaultBrush;
hoverPen = defaultPen; hoverPen = defaultPen;
if(isHorizonLayout) if(isHorizonLayout)
hoverPen.setWidth(2); 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 //focus state
focusBrush = option->palette.brush(QPalette::Active, QPalette::Base); focusBrush = option->palette.brush(QPalette::Active, QPalette::Base);
@ -3782,7 +3792,7 @@ void KFashionStyleParameters::initMenuParameters(bool isDark, const QStyleOption
QPainter pixmapPainter(&framePixmap); QPainter pixmapPainter(&framePixmap);
pixmapPainter.setPen(Qt::NoPen); 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.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
pixmapPainter.drawPath(drawRectPath); pixmapPainter.drawPath(drawRectPath);
pixmapPainter.end(); pixmapPainter.end();

View File

@ -80,7 +80,7 @@ public:
int ToolButton_DefaultWidth = 60; int ToolButton_DefaultWidth = 60;
int IconButton_DefaultWidth = 36; int IconButton_DefaultWidth = 36;
int IconButton_DefaultWidth_origin = 36; int IconButton_DefaultWidth_origin = 36;
QColor ColoseButtonColor = QColor(243, 34, 45); QColor ColoseButtonColor;
// menu // menu
int Menu_MarginHeight = 4 + 8; int Menu_MarginHeight = 4 + 8;
@ -114,6 +114,7 @@ public:
int Slider_Length_origin = 20; int Slider_Length_origin = 20;
int Slider_GrooveLength = 4; int Slider_GrooveLength = 4;
int Slider_GrooveLength_origin = 4; int Slider_GrooveLength_origin = 4;
int Slider_Margin = 2;
// radiobutton // radiobutton
int ExclusiveIndicator_Width = 16; int ExclusiveIndicator_Width = 16;
@ -142,6 +143,7 @@ public:
int ComboBox_DefaultMenuItemHeight = 36; int ComboBox_DefaultMenuItemHeight = 36;
int ComboBox_DefaultMenuItemHeight_original = 36; int ComboBox_DefaultMenuItemHeight_original = 36;
int ComboBox_FrameWidth = 2; int ComboBox_FrameWidth = 2;
int ComboBox_VMargin = 1;
// spinbox // spinbox
int SpinBox_DefaultWidth = 160; int SpinBox_DefaultWidth = 160;

View File

@ -268,9 +268,6 @@ int Qt5UKUIStyle::styleHint(QStyle::StyleHint hint, const QStyleOption *option,
} }
return m_is_tablet_mode; return m_is_tablet_mode;
case SH_Button_FocusPolicy:
return Qt::TabFocus;
default: default:
break; break;
} }
@ -465,7 +462,8 @@ void Qt5UKUIStyle::polish(QWidget *widget)
if (qobject_cast<QTabWidget*>(widget)) { if (qobject_cast<QTabWidget*>(widget)) {
//FIXME: unpolish, extensiable. //FIXME: unpolish, extensiable.
m_tab_animation_helper->registerWidget(widget); if (qAppName() != "ukui-sidebar")
m_tab_animation_helper->registerWidget(widget);
} }
if (qobject_cast<QScrollBar*>(widget)) { if (qobject_cast<QScrollBar*>(widget)) {
@ -478,7 +476,8 @@ void Qt5UKUIStyle::polish(QWidget *widget)
if (auto v = qobject_cast<QAbstractItemView *>(widget)) { if (auto v = qobject_cast<QAbstractItemView *>(widget)) {
v->viewport()->setAttribute(Qt::WA_Hover); v->viewport()->setAttribute(Qt::WA_Hover);
v->setAttribute(Qt::WA_InputMethodEnabled); //QCompleter BUG113969
// v->setAttribute(Qt::WA_InputMethodEnabled);
} }
if(qobject_cast<QToolButton*>(widget)) if(qobject_cast<QToolButton*>(widget))
@ -750,7 +749,7 @@ QPixmap Qt5UKUIStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &p
// return QPixmap::fromImage(im); // 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); QColor bg = option->palette.color(QPalette::Disabled, QPalette::WindowText);
bg.setAlphaF(0.5); bg.setAlphaF(0.5);
QPainter p(&target); QPainter p(&target);
@ -1930,6 +1929,14 @@ void Qt5UKUIStyle::drawPrimitive(QStyle::PrimitiveElement element, const QStyleO
painter->setBrush(button_Hover(option)); painter->setBrush(button_Hover(option));
painter->drawRoundedRect(option->rect, iconMode_Radius, iconMode_Radius); 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(); painter->restore();
} }
} else { } else {
@ -1941,6 +1948,7 @@ void Qt5UKUIStyle::drawPrimitive(QStyle::PrimitiveElement element, const QStyleO
} }
painter->save(); painter->save();
painter->setRenderHint(QPainter::Antialiasing, true);
painter->setPen(Qt::NoPen); painter->setPen(Qt::NoPen);
if (!enable) { if (!enable) {
painter->setBrush(disableBrush); painter->setBrush(disableBrush);
@ -2096,28 +2104,55 @@ void Qt5UKUIStyle::drawComplexControl(QStyle::ComplexControl control, const QSty
if (slider->subControls & SC_SliderGroove) { if (slider->subControls & SC_SliderGroove) {
if (horizontal) { if (horizontal) {
groove.setHeight(sp->Slider_GrooveLength); groove.setHeight(sp->Slider_GrooveLength);
groove.setWidth(groove.width() - 2 * sp->Slider_Margin);
} else { } else {
groove.setWidth(sp->Slider_GrooveLength); 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; QBrush sBrush, gBrush;
QRect sRect, gRect; QRect sRect, gRect;
if (horizontal) { if (horizontal) {
if (slider->upsideDown) { if (slider->upsideDown) {
sRect.setRect(handle.center().x(), groove.y(), groove.width() - handle.center().x(), groove.height()); sRect.setLeft(handle.center().x());
gRect.setRect(groove.x(), groove.y(), handle.center().x(), groove.height()); 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 { } else {
sRect.setRect(groove.x(), groove.y(), handle.center().x(), groove.height()); gRect.setLeft(handle.center().x());
gRect.setRect(handle.center().x(), groove.y(), groove.width() - handle.center().x(), groove.height()); 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 { } else {
if (slider->upsideDown) { if (slider->upsideDown) {
sRect.setRect(groove.x(), handle.center().y(), groove.width(), groove.height() - handle.center().y()); gRect.setLeft(groove.left());
gRect.setRect(groove.x(), groove.y(), groove.width(), handle.center().y()); 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 { } else {
sRect.setRect(groove.x(), groove.y(), groove.width(), groove.center().y()); sRect.setLeft(groove.left());
gRect.setRect(groove.x(), handle.center().y(), groove.width(), groove.height() - handle.center().y()); 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) { while (v <= slider->maximum) {
int pos = sliderPositionFromValue(slider->minimum, slider->maximum, v, proxy()->pixelMetric(PM_SliderSpaceAvailable, option, widget), int pos = sliderPositionFromValue(slider->minimum, slider->maximum, v, proxy()->pixelMetric(PM_SliderSpaceAvailable, option, widget),
slider->upsideDown) + len / 2; slider->upsideDown) + len / 2;
pos = pos + sp->Slider_Margin;
if (horizontal) { if (horizontal) {
if (slider->tickPosition & QSlider::TicksAbove) if (slider->tickPosition & QSlider::TicksAbove)
painter->drawLine(pos, handle.top() - thickSpace, pos, handle.top() - thickSpace + tick); 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 //we need to reinit our brush because it has QGradient without use option rect
QStyleOptionSlider handleOption = *slider; QStyleOptionSlider handleOption = *slider;
handleOption.rect = handle; 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); sp->initSliderParameters(isUseDarkPalette(), &handleOption, widget);
QBrush hBrush; QBrush hBrush;
@ -3392,7 +3433,6 @@ void Qt5UKUIStyle::drawControl(QStyle::ControlElement element, const QStyleOptio
} }
painter->save(); painter->save();
painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
if (verticalTabs) { if (verticalTabs) {
int newX, newY, newRot; int newX, newY, newRot;
if (tab->shape == QTabBar::RoundedEast || tab->shape == QTabBar::TriangularEast) { 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()) { if (!tab->icon.isNull()) {
painter->save();
painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
QIcon::Mode mode = (tab->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled; QIcon::Mode mode = (tab->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled;
QPixmap pixmap = tab->icon.pixmap(widget ? widget->window()->windowHandle() : 0, tab->iconSize, QPixmap pixmap = tab->icon.pixmap(widget ? widget->window()->windowHandle() : 0, tab->iconSize,
mode, (tab->state & State_Selected) ? QIcon::On : QIcon::Off); mode, (tab->state & State_Selected) ? QIcon::On : QIcon::Off);
pixmap = proxy()->generatedIconPixmap(mode, pixmap, option); pixmap = proxy()->generatedIconPixmap(mode, pixmap, option);
QPixmap drawPixmap = HighLightEffect::ordinaryGeneratePixmap(pixmap, option, widget); QPixmap drawPixmap = HighLightEffect::ordinaryGeneratePixmap(pixmap, option, widget);
painter->drawPixmap(iconRect.x(), iconRect.y(), drawPixmap); 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(); painter->restore();
//draw separate line //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 it's comobobox popup, set combobox popup size rect
if (isComboBox) { if (isComboBox) {
int MenuItem_HMargin = proxy()->pixelMetric(PM_MenuVMargin, option, widget); 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)) { if (enable && (selected | sunken)) {
@ -4211,6 +4254,7 @@ void Qt5UKUIStyle::drawControl(QStyle::ControlElement element, const QStyleOptio
case CE_ShapedFrame: case CE_ShapedFrame:
if (const QStyleOptionFrame *f = qstyleoption_cast<const QStyleOptionFrame *>(option)) { if (const QStyleOptionFrame *f = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
painter->save();
int frameShape = f->frameShape; int frameShape = f->frameShape;
int frameShadow = QFrame::Plain; int frameShadow = QFrame::Plain;
if (f->state & QStyle::State_Sunken) { if (f->state & QStyle::State_Sunken) {
@ -4235,12 +4279,14 @@ void Qt5UKUIStyle::drawControl(QStyle::ControlElement element, const QStyleOptio
} }
if (frameShadow == QFrame::Plain) { if (frameShadow == QFrame::Plain) {
QPen oldPen = painter->pen(); 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->drawLine(p1, p2);
painter->setPen(oldPen); painter->setPen(oldPen);
} else { } else {
qDrawShadeLine(painter, p1, p2, f->palette, frameShadow == QFrame::Sunken, lw, mlw); qDrawShadeLine(painter, p1, p2, f->palette, frameShadow == QFrame::Sunken, lw, mlw);
} }
painter->restore();
break; break;
} }
case QFrame::WinPanel: case QFrame::WinPanel:
@ -4250,6 +4296,7 @@ void Qt5UKUIStyle::drawControl(QStyle::ControlElement element, const QStyleOptio
Style::drawControl(element, option, painter, widget); Style::drawControl(element, option, painter, widget);
} }
} }
painter->restore();
break; break;
default: default:
return Style::drawControl(element, option, painter, widget); 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<const QStyleOptionSlider *>(option)) { if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
if (sl->orientation == Qt::Horizontal) 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 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 { } else {
return 0; return 0;
} }
@ -4512,9 +4559,9 @@ QRect Qt5UKUIStyle::subControlRect(QStyle::ComplexControl control, const QStyleO
int sliderPos = sliderPositionFromValue(slider->minimum, slider->maximum, slider->sliderPosition, int sliderPos = sliderPositionFromValue(slider->minimum, slider->maximum, slider->sliderPosition,
proxy()->pixelMetric(PM_SliderSpaceAvailable, option, widget), slider->upsideDown); proxy()->pixelMetric(PM_SliderSpaceAvailable, option, widget), slider->upsideDown);
if (horizontal) { if (horizontal) {
handleRect.moveLeft(sliderPos); handleRect.moveLeft(sliderPos + sp->Slider_Margin);
} else { } else {
handleRect.moveTop((sliderPos)); handleRect.moveTop((sliderPos + sp->Slider_Margin));
} }
return visualRect(slider->direction, slider->rect, handleRect); 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.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) { if (widget) {
@ -5507,18 +5555,10 @@ QSize Qt5UKUIStyle::sizeFromContents(ContentsType ct, const QStyleOption *option
if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) { if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
const bool horizontal(slider->orientation == Qt::Horizontal); const bool horizontal(slider->orientation == Qt::Horizontal);
if (horizontal) { if (horizontal) {
newSize.setWidth(newSize.height() * sp->m_scaleRatio2_1); newSize.setHeight(newSize.height() + 2 * sp->Slider_Margin);
if (slider->tickPosition & QSlider::TicksAbove)
newSize.setHeight(newSize.height() - 3);
if (slider->tickPosition & QSlider::TicksBelow)
newSize.setHeight(newSize.height() - 3);
newSize.setWidth(qMax(newSize.width(), sp->Slider_DefaultLength)); newSize.setWidth(qMax(newSize.width(), sp->Slider_DefaultLength));
} else { } else {
newSize.setWidth(newSize.width() * sp->m_scaleRatio2_1); newSize.setWidth(newSize.width() + 2 * sp->Slider_Margin);
if (slider->tickPosition & QSlider::TicksAbove)
newSize.setWidth(newSize.width() - 3);
if (slider->tickPosition & QSlider::TicksBelow)
newSize.setWidth(newSize.width() - 3);
newSize.setHeight(qMax(newSize.height(), sp->Slider_DefaultLength)); newSize.setHeight(qMax(newSize.height(), sp->Slider_DefaultLength));
} }
return newSize; return newSize;

View File

@ -1,5 +1,6 @@
#include "qt5-ukui-style.h" #include "qt5-ukui-style.h"
#include <QListView>
#include <QTreeView>
static QSizeF viewItemTextLayout(QTextLayout &textLayout, int lineWidth, int maxHeight = -1, int *lastVisibleLine = nullptr) 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: case Qt::DecorationRole:
{ {
if (option->features & QStyleOptionViewItem::HasDecoration) { if (option->features & QStyleOptionViewItem::HasDecoration) {
if(widget){
if(qobject_cast<const QListView *>(widget)){
QSize size = qobject_cast<const QListView *>(widget)->iconSize();
return QSize(qMax(option->decorationSize.width(), size.width()),
qMax(option->decorationSize.height(), size.height()));
}
if(qobject_cast<const QTreeView *>(widget)){
QSize size = qobject_cast<const QTreeView *>(widget)->iconSize();
return QSize(qMax(option->decorationSize.width(), size.width()),
qMax(option->decorationSize.height(), size.height()));
}
}
return option->decorationSize; return option->decorationSize;
} }
break; break;