577 lines
26 KiB
Diff
577 lines
26 KiB
Diff
diff --git a/common/common.pro b/common/common.pro
|
|
index c244613..99bb9e3 100644
|
|
--- a/common/common.pro
|
|
+++ b/common/common.pro
|
|
@@ -8,7 +8,6 @@ CONFIG += c++11 \
|
|
QT += core \
|
|
dbus \
|
|
theme_support-private \
|
|
- x11extras \
|
|
widgets
|
|
|
|
PKGCONFIG += gtk+-3.0 \
|
|
diff --git a/common/gnomehintssettings.cpp b/common/gnomehintssettings.cpp
|
|
index 4cc19b2..8a3b980 100644
|
|
--- a/common/gnomehintssettings.cpp
|
|
+++ b/common/gnomehintssettings.cpp
|
|
@@ -36,8 +36,6 @@
|
|
#include <QDBusConnection>
|
|
#include <QDBusMessage>
|
|
|
|
-#include <QX11Info>
|
|
-
|
|
Q_LOGGING_CATEGORY(QGnomePlatform, "qt.qpa.qgnomeplatform")
|
|
|
|
const QDBusArgument &operator>>(const QDBusArgument &argument, QMap<QString, QVariantMap> &map)
|
|
@@ -135,7 +133,7 @@ GnomeHintsSettings::GnomeHintsSettings()
|
|
QStringLiteral("SettingChanged"), this, SLOT(portalSettingChanged(QString,QString,QDBusVariant)));
|
|
}
|
|
|
|
- if (!QX11Info::isPlatformX11())
|
|
+ if (QGuiApplication::platformName() != QStringLiteral("xcb"))
|
|
cursorSizeChanged();
|
|
|
|
loadFonts();
|
|
@@ -172,7 +170,7 @@ void GnomeHintsSettings::gsettingPropertyChanged(GSettings *settings, gchar *key
|
|
} else if (changedProperty == QStringLiteral("monospace-font-name")) {
|
|
gnomeHintsSettings->fontChanged();
|
|
} else if (changedProperty == QStringLiteral("cursor-size")) {
|
|
- if (!QX11Info::isPlatformX11())
|
|
+ if (QGuiApplication::platformName() != QStringLiteral("xcb"))
|
|
gnomeHintsSettings->cursorSizeChanged();
|
|
// Org.gnome.wm.preferences
|
|
} else if (changedProperty == QStringLiteral("titlebar-font")) {
|
|
@@ -359,7 +357,7 @@ void GnomeHintsSettings::loadFonts()
|
|
bool bold = false;
|
|
int fontSize;
|
|
QString name;
|
|
- QRegExp re("(.+)[ \t]+([0-9]+)");
|
|
+ QRegExp re("^([^,]+)[, \t]+([0-9]+)$");
|
|
if (re.indexIn(fontName) == 0) {
|
|
fontSize = re.cap(2).toInt();
|
|
name = re.cap(1);
|
|
diff --git a/common/gnomehintssettings.h b/common/gnomehintssettings.h
|
|
index 46580ff..2bce415 100644
|
|
--- a/common/gnomehintssettings.h
|
|
+++ b/common/gnomehintssettings.h
|
|
@@ -24,8 +24,10 @@
|
|
#include <QFont>
|
|
#include <QFlags>
|
|
#include <QObject>
|
|
+#include <QPalette>
|
|
#include <QVariant>
|
|
|
|
+#include <cmath>
|
|
#include <memory>
|
|
|
|
#undef signals
|
|
@@ -36,7 +38,6 @@
|
|
|
|
#include <qpa/qplatformtheme.h>
|
|
|
|
-
|
|
class GnomeHintsSettings : public QObject
|
|
{
|
|
Q_OBJECT
|
|
@@ -56,6 +57,73 @@ public:
|
|
explicit GnomeHintsSettings();
|
|
virtual ~GnomeHintsSettings();
|
|
|
|
+ // Borrowed from the KColorUtils code
|
|
+ static QColor mix(const QColor &c1, const QColor &c2, qreal bias = 0.5)
|
|
+ {
|
|
+ auto mixQreal = [](qreal a, qreal b, qreal bias) {
|
|
+ return a + (b - a) * bias;
|
|
+ };
|
|
+
|
|
+ if (bias <= 0.0)
|
|
+ return c1;
|
|
+ if (bias >= 1.0)
|
|
+ return c2;
|
|
+ if (std::isnan(bias))
|
|
+ return c1;
|
|
+
|
|
+ qreal r = mixQreal(c1.redF(), c2.redF(), bias);
|
|
+ qreal g = mixQreal(c1.greenF(), c2.greenF(), bias);
|
|
+ qreal b = mixQreal(c1.blueF(), c2.blueF(), bias);
|
|
+ qreal a = mixQreal(c1.alphaF(), c2.alphaF(), bias);
|
|
+
|
|
+ return QColor::fromRgbF(r, g, b, a);
|
|
+ }
|
|
+
|
|
+ static QColor lighten(const QColor &color, qreal amount = 0.1)
|
|
+ {
|
|
+ qreal h, s, l, a;
|
|
+ color.getHslF(&h, &s, &l, &a);
|
|
+
|
|
+ qreal lightness = l + amount;
|
|
+ if (lightness > 1)
|
|
+ lightness = 1;
|
|
+ return QColor::fromHslF(h, s, lightness, a);
|
|
+ }
|
|
+
|
|
+ static QColor darken(const QColor &color, qreal amount = 0.1)
|
|
+ {
|
|
+ qreal h, s, l, a;
|
|
+ color.getHslF(&h, &s, &l, &a);
|
|
+
|
|
+ qreal lightness = l - amount;
|
|
+ if (lightness < 0)
|
|
+ lightness = 0;
|
|
+
|
|
+ return QColor::fromHslF(h, s, lightness, a);
|
|
+ }
|
|
+
|
|
+ static QColor desaturate(const QColor &color, qreal amount = 0.1)
|
|
+ {
|
|
+ qreal h, s, l, a;
|
|
+ color.getHslF(&h, &s, &l, &a);
|
|
+
|
|
+ qreal saturation = s - amount;
|
|
+ if (saturation < 0)
|
|
+ saturation = 0;
|
|
+ return QColor::fromHslF(h, saturation, l, a);
|
|
+ }
|
|
+
|
|
+ static QColor transparentize(const QColor &color, qreal amount = 0.1)
|
|
+ {
|
|
+ qreal h, s, l, a;
|
|
+ color.getHslF(&h, &s, &l, &a);
|
|
+
|
|
+ qreal alpha = a - amount;
|
|
+ if (alpha < 0)
|
|
+ alpha = 0;
|
|
+ return QColor::fromHslF(h, s, l, alpha);
|
|
+ }
|
|
+
|
|
inline QFont * font(QPlatformTheme::Font type) const
|
|
{
|
|
if (m_fonts.contains(type)) {
|
|
@@ -68,6 +136,198 @@ public:
|
|
}
|
|
}
|
|
|
|
+ inline QPalette * palette() const
|
|
+ {
|
|
+ QPalette *palette = new QPalette;
|
|
+
|
|
+ if (m_gtkThemeDarkVariant) {
|
|
+ // Colors defined in GTK adwaita style in _colors.scss
|
|
+ QColor base_color = lighten(desaturate(QColor("#241f31"), 1.0), 0.02);
|
|
+ QColor text_color = QColor("white");
|
|
+ QColor bg_color = darken(desaturate(QColor("#3d3846"), 1.0), 0.04);
|
|
+ QColor fg_color = QColor("#eeeeec");
|
|
+ QColor selected_bg_color = darken(QColor("#3584e4"), 0.2);
|
|
+ QColor selected_fg_color = QColor("white");
|
|
+ QColor osd_text_color = QColor("white");
|
|
+ QColor osd_bg_color = QColor("black");
|
|
+ QColor shadow = transparentize(QColor("black"), 0.9);
|
|
+
|
|
+ QColor backdrop_fg_color = mix(fg_color, bg_color);
|
|
+ QColor backdrop_base_color = lighten(base_color, 0.01);
|
|
+ QColor backdrop_selected_fg_color = mix(text_color, backdrop_base_color, 0.2);
|
|
+
|
|
+ // This is the color we use as initial color for the gradient in normal state
|
|
+ // Defined in _drawing.scss button(normal)
|
|
+ QColor button_base_color = darken(bg_color, 0.01);
|
|
+
|
|
+ QColor link_color = lighten(selected_bg_color, 0.2);
|
|
+ QColor link_visited_color = lighten(selected_bg_color, 0.1);
|
|
+
|
|
+ palette->setColor(QPalette::All, QPalette::Window, bg_color);
|
|
+ palette->setColor(QPalette::All, QPalette::WindowText, fg_color);
|
|
+ palette->setColor(QPalette::All, QPalette::Base, base_color);
|
|
+ palette->setColor(QPalette::All, QPalette::AlternateBase, base_color);
|
|
+ palette->setColor(QPalette::All, QPalette::ToolTipBase, osd_bg_color);
|
|
+ palette->setColor(QPalette::All, QPalette::ToolTipText, osd_text_color);
|
|
+ palette->setColor(QPalette::All, QPalette::Text, fg_color);
|
|
+ palette->setColor(QPalette::All, QPalette::Button, button_base_color);
|
|
+ palette->setColor(QPalette::All, QPalette::ButtonText, fg_color);
|
|
+ palette->setColor(QPalette::All, QPalette::BrightText, text_color);
|
|
+
|
|
+ palette->setColor(QPalette::All, QPalette::Light, lighten(button_base_color));
|
|
+ palette->setColor(QPalette::All, QPalette::Midlight, mix(lighten(button_base_color), button_base_color));
|
|
+ palette->setColor(QPalette::All, QPalette::Mid, mix(darken(button_base_color), button_base_color));
|
|
+ palette->setColor(QPalette::All, QPalette::Dark, darken(button_base_color));
|
|
+ palette->setColor(QPalette::All, QPalette::Shadow, shadow);
|
|
+
|
|
+ palette->setColor(QPalette::All, QPalette::Highlight, selected_bg_color);
|
|
+ palette->setColor(QPalette::All, QPalette::HighlightedText, selected_fg_color);
|
|
+
|
|
+ palette->setColor(QPalette::All, QPalette::Link, link_color);
|
|
+ palette->setColor(QPalette::All, QPalette::LinkVisited, link_visited_color);
|
|
+
|
|
+
|
|
+ QColor insensitive_fg_color = mix(fg_color, bg_color);
|
|
+ QColor insensitive_bg_color = mix(bg_color, base_color, 0.4);
|
|
+
|
|
+ palette->setColor(QPalette::Disabled, QPalette::Window, insensitive_bg_color);
|
|
+ palette->setColor(QPalette::Disabled, QPalette::WindowText, insensitive_fg_color);
|
|
+ palette->setColor(QPalette::Disabled, QPalette::Base, base_color);
|
|
+ palette->setColor(QPalette::Disabled, QPalette::AlternateBase, base_color);
|
|
+ palette->setColor(QPalette::Disabled, QPalette::Text, insensitive_fg_color);
|
|
+ palette->setColor(QPalette::Disabled, QPalette::Button, insensitive_bg_color);
|
|
+ palette->setColor(QPalette::Disabled, QPalette::ButtonText, insensitive_fg_color);
|
|
+ palette->setColor(QPalette::Disabled, QPalette::BrightText, text_color);
|
|
+
|
|
+ palette->setColor(QPalette::Disabled, QPalette::Light, lighten(insensitive_bg_color));
|
|
+ palette->setColor(QPalette::Disabled, QPalette::Midlight, mix(lighten(insensitive_bg_color), insensitive_bg_color));
|
|
+ palette->setColor(QPalette::Disabled, QPalette::Mid, mix(darken(insensitive_bg_color), insensitive_bg_color));
|
|
+ palette->setColor(QPalette::Disabled, QPalette::Dark, darken(insensitive_bg_color));
|
|
+ palette->setColor(QPalette::Disabled, QPalette::Shadow, shadow);
|
|
+
|
|
+ palette->setColor(QPalette::Disabled, QPalette::Highlight, selected_bg_color);
|
|
+ palette->setColor(QPalette::Disabled, QPalette::HighlightedText, selected_fg_color);
|
|
+
|
|
+ palette->setColor(QPalette::Disabled, QPalette::Link, link_color);
|
|
+ palette->setColor(QPalette::Disabled, QPalette::LinkVisited, link_visited_color);
|
|
+
|
|
+
|
|
+ palette->setColor(QPalette::Inactive, QPalette::Window, bg_color);
|
|
+ palette->setColor(QPalette::Inactive, QPalette::WindowText, backdrop_fg_color);
|
|
+ palette->setColor(QPalette::Inactive, QPalette::Base, backdrop_base_color);
|
|
+ palette->setColor(QPalette::Inactive, QPalette::AlternateBase, backdrop_base_color);
|
|
+ palette->setColor(QPalette::Inactive, QPalette::Text, backdrop_fg_color);
|
|
+ palette->setColor(QPalette::Inactive, QPalette::Button, button_base_color);
|
|
+ palette->setColor(QPalette::Inactive, QPalette::ButtonText, backdrop_fg_color);
|
|
+ palette->setColor(QPalette::Inactive, QPalette::BrightText, text_color);
|
|
+
|
|
+ palette->setColor(QPalette::Inactive, QPalette::Light, lighten(insensitive_bg_color));
|
|
+ palette->setColor(QPalette::Inactive, QPalette::Midlight, mix(lighten(insensitive_bg_color), insensitive_bg_color));
|
|
+ palette->setColor(QPalette::Inactive, QPalette::Mid, mix(darken(insensitive_bg_color), insensitive_bg_color));
|
|
+ palette->setColor(QPalette::Inactive, QPalette::Dark, darken(insensitive_bg_color));
|
|
+ palette->setColor(QPalette::Inactive, QPalette::Shadow, shadow);
|
|
+
|
|
+ palette->setColor(QPalette::Inactive, QPalette::Highlight, selected_bg_color);
|
|
+ palette->setColor(QPalette::Inactive, QPalette::HighlightedText, backdrop_selected_fg_color);
|
|
+
|
|
+ palette->setColor(QPalette::Inactive, QPalette::Link, link_color);
|
|
+ palette->setColor(QPalette::Inactive, QPalette::LinkVisited, link_visited_color);
|
|
+ } else {
|
|
+ // Colors defined in GTK adwaita style in _colors.scss
|
|
+ QColor base_color = QColor("white");
|
|
+ QColor text_color = QColor("black");
|
|
+ QColor bg_color = QColor("#f6f5f4");
|
|
+ QColor fg_color = QColor("#2e3436");
|
|
+ QColor selected_bg_color = QColor("#3584e4");
|
|
+ QColor selected_fg_color = QColor("white");
|
|
+ QColor osd_text_color = QColor("white");
|
|
+ QColor osd_bg_color = QColor("black");
|
|
+ QColor shadow = transparentize(QColor("black"), 0.9);
|
|
+
|
|
+ QColor backdrop_fg_color = mix(fg_color, bg_color);
|
|
+ QColor backdrop_base_color = darken(base_color, 0.01);
|
|
+ QColor backdrop_selected_fg_color = backdrop_base_color;
|
|
+
|
|
+ // This is the color we use as initial color for the gradient in normal state
|
|
+ // Defined in _drawing.scss button(normal)
|
|
+ QColor button_base_color = darken(bg_color, 0.04);
|
|
+
|
|
+ QColor link_color = darken(selected_bg_color, 0.1);
|
|
+ QColor link_visited_color = darken(selected_bg_color, 0.2);
|
|
+
|
|
+ palette->setColor(QPalette::All, QPalette::Window, bg_color);
|
|
+ palette->setColor(QPalette::All, QPalette::WindowText, fg_color);
|
|
+ palette->setColor(QPalette::All, QPalette::Base, base_color);
|
|
+ palette->setColor(QPalette::All, QPalette::AlternateBase, base_color);
|
|
+ palette->setColor(QPalette::All, QPalette::ToolTipBase, osd_bg_color);
|
|
+ palette->setColor(QPalette::All, QPalette::ToolTipText, osd_text_color);
|
|
+ palette->setColor(QPalette::All, QPalette::Text, fg_color);
|
|
+ palette->setColor(QPalette::All, QPalette::Button, button_base_color);
|
|
+ palette->setColor(QPalette::All, QPalette::ButtonText, fg_color);
|
|
+ palette->setColor(QPalette::All, QPalette::BrightText, text_color);
|
|
+
|
|
+ palette->setColor(QPalette::All, QPalette::Light, lighten(button_base_color));
|
|
+ palette->setColor(QPalette::All, QPalette::Midlight, mix(lighten(button_base_color), button_base_color));
|
|
+ palette->setColor(QPalette::All, QPalette::Mid, mix(darken(button_base_color), button_base_color));
|
|
+ palette->setColor(QPalette::All, QPalette::Dark, darken(button_base_color));
|
|
+ palette->setColor(QPalette::All, QPalette::Shadow, shadow);
|
|
+
|
|
+ palette->setColor(QPalette::All, QPalette::Highlight, selected_bg_color);
|
|
+ palette->setColor(QPalette::All, QPalette::HighlightedText, selected_fg_color);
|
|
+
|
|
+ palette->setColor(QPalette::All, QPalette::Link, link_color);
|
|
+ palette->setColor(QPalette::All, QPalette::LinkVisited, link_visited_color);
|
|
+
|
|
+ QColor insensitive_fg_color = mix(fg_color, bg_color);
|
|
+ QColor insensitive_bg_color = mix(bg_color, base_color, 0.4);
|
|
+
|
|
+ palette->setColor(QPalette::Disabled, QPalette::Window, insensitive_bg_color);
|
|
+ palette->setColor(QPalette::Disabled, QPalette::WindowText, insensitive_fg_color);
|
|
+ palette->setColor(QPalette::Disabled, QPalette::Base, base_color);
|
|
+ palette->setColor(QPalette::Disabled, QPalette::AlternateBase, base_color);
|
|
+ palette->setColor(QPalette::Disabled, QPalette::Text, insensitive_fg_color);
|
|
+ palette->setColor(QPalette::Disabled, QPalette::Button, insensitive_bg_color);
|
|
+ palette->setColor(QPalette::Disabled, QPalette::ButtonText, insensitive_fg_color);
|
|
+ palette->setColor(QPalette::Disabled, QPalette::BrightText, text_color);
|
|
+
|
|
+ palette->setColor(QPalette::Disabled, QPalette::Light, lighten(insensitive_bg_color));
|
|
+ palette->setColor(QPalette::Disabled, QPalette::Midlight, mix(lighten(insensitive_bg_color), insensitive_bg_color));
|
|
+ palette->setColor(QPalette::Disabled, QPalette::Mid, mix(darken(insensitive_bg_color), insensitive_bg_color));
|
|
+ palette->setColor(QPalette::Disabled, QPalette::Dark, darken(insensitive_bg_color));
|
|
+ palette->setColor(QPalette::Disabled, QPalette::Shadow, shadow);
|
|
+
|
|
+ palette->setColor(QPalette::Disabled, QPalette::Highlight, selected_bg_color);
|
|
+ palette->setColor(QPalette::Disabled, QPalette::HighlightedText, selected_fg_color);
|
|
+
|
|
+ palette->setColor(QPalette::Disabled, QPalette::Link, link_color);
|
|
+ palette->setColor(QPalette::Disabled, QPalette::LinkVisited, link_visited_color);
|
|
+
|
|
+
|
|
+ palette->setColor(QPalette::Inactive, QPalette::Window, bg_color);
|
|
+ palette->setColor(QPalette::Inactive, QPalette::WindowText, backdrop_fg_color);
|
|
+ palette->setColor(QPalette::Inactive, QPalette::Base, backdrop_base_color);
|
|
+ palette->setColor(QPalette::Inactive, QPalette::AlternateBase, backdrop_base_color);
|
|
+ palette->setColor(QPalette::Inactive, QPalette::Text, backdrop_fg_color);
|
|
+ palette->setColor(QPalette::Inactive, QPalette::Button, button_base_color);
|
|
+ palette->setColor(QPalette::Inactive, QPalette::ButtonText, backdrop_fg_color);
|
|
+ palette->setColor(QPalette::Inactive, QPalette::BrightText, text_color);
|
|
+
|
|
+ palette->setColor(QPalette::Inactive, QPalette::Light, lighten(insensitive_bg_color));
|
|
+ palette->setColor(QPalette::Inactive, QPalette::Midlight, mix(lighten(insensitive_bg_color), insensitive_bg_color));
|
|
+ palette->setColor(QPalette::Inactive, QPalette::Mid, mix(darken(insensitive_bg_color), insensitive_bg_color));
|
|
+ palette->setColor(QPalette::Inactive, QPalette::Dark, darken(insensitive_bg_color));
|
|
+ palette->setColor(QPalette::Inactive, QPalette::Shadow, shadow);
|
|
+
|
|
+ palette->setColor(QPalette::Inactive, QPalette::Highlight, selected_bg_color);
|
|
+ palette->setColor(QPalette::Inactive, QPalette::HighlightedText, backdrop_selected_fg_color);
|
|
+
|
|
+ palette->setColor(QPalette::Inactive, QPalette::Link, link_color);
|
|
+ palette->setColor(QPalette::Inactive, QPalette::LinkVisited, link_visited_color);
|
|
+ }
|
|
+
|
|
+ return palette;
|
|
+ }
|
|
+
|
|
inline bool gtkThemeDarkVariant() const
|
|
{
|
|
return m_gtkThemeDarkVariant;
|
|
diff --git a/common/qgtk3dialoghelpers.cpp b/common/qgtk3dialoghelpers.cpp
|
|
index f4bf372..a33d0d1 100644
|
|
--- a/common/qgtk3dialoghelpers.cpp
|
|
+++ b/common/qgtk3dialoghelpers.cpp
|
|
@@ -87,24 +87,18 @@ Q_SIGNALS:
|
|
|
|
protected:
|
|
static void onResponse(QGtk3Dialog *dialog, int response);
|
|
- static void onUpdatePreview(QGtk3Dialog *dialog);
|
|
|
|
private slots:
|
|
void onParentWindowDestroyed();
|
|
|
|
private:
|
|
GtkWidget *gtkWidget;
|
|
- GtkWidget *previewWidget;
|
|
};
|
|
|
|
QGtk3Dialog::QGtk3Dialog(GtkWidget *gtkWidget) : gtkWidget(gtkWidget)
|
|
{
|
|
g_signal_connect_swapped(G_OBJECT(gtkWidget), "response", G_CALLBACK(onResponse), this);
|
|
g_signal_connect(G_OBJECT(gtkWidget), "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL);
|
|
-
|
|
- previewWidget = gtk_image_new();
|
|
- g_signal_connect_swapped(G_OBJECT(gtkWidget), "update-preview", G_CALLBACK(onUpdatePreview), this);
|
|
- gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(gtkWidget), previewWidget);
|
|
}
|
|
|
|
QGtk3Dialog::~QGtk3Dialog()
|
|
@@ -180,32 +174,6 @@ void QGtk3Dialog::onResponse(QGtk3Dialog *dialog, int response)
|
|
emit dialog->reject();
|
|
}
|
|
|
|
-void QGtk3Dialog::onUpdatePreview(QGtk3Dialog *dialog) {
|
|
- gchar *filename = gtk_file_chooser_get_preview_filename(GTK_FILE_CHOOSER(dialog->gtkWidget));
|
|
- if (!filename) {
|
|
- gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(dialog->gtkWidget), false);
|
|
- return;
|
|
- }
|
|
-
|
|
- // Don't attempt to open anything which isn't a regular file. If a named pipe,
|
|
- // this may hang. See https://crbug.com/534754.
|
|
- QFileInfo fileinfo(filename);
|
|
- if (!fileinfo.exists() || !fileinfo.isFile()) {
|
|
- g_free(filename);
|
|
- gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(dialog->gtkWidget), false);
|
|
- return;
|
|
- }
|
|
-
|
|
- // This will preserve the image's aspect ratio.
|
|
- GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_size(filename, PREVIEW_WIDTH, PREVIEW_HEIGHT, 0);
|
|
- g_free(filename);
|
|
- if (pixbuf) {
|
|
- gtk_image_set_from_pixbuf(GTK_IMAGE(dialog->previewWidget), pixbuf);
|
|
- g_object_unref(pixbuf);
|
|
- }
|
|
- gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(dialog->gtkWidget), pixbuf ? true : false);
|
|
-}
|
|
-
|
|
void QGtk3Dialog::onParentWindowDestroyed()
|
|
{
|
|
// The QGtk3*DialogHelper classes own this object. Make sure the parent doesn't delete it.
|
|
@@ -293,12 +261,21 @@ QGtk3FileDialogHelper::QGtk3FileDialogHelper()
|
|
|
|
g_signal_connect(GTK_FILE_CHOOSER(d->gtkDialog()), "selection-changed", G_CALLBACK(onSelectionChanged), this);
|
|
g_signal_connect_swapped(GTK_FILE_CHOOSER(d->gtkDialog()), "current-folder-changed", G_CALLBACK(onCurrentFolderChanged), this);
|
|
+
|
|
+ previewWidget = gtk_image_new();
|
|
+ g_signal_connect(G_OBJECT(d->gtkDialog()), "update-preview", G_CALLBACK(onUpdatePreview), this);
|
|
+ gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(d->gtkDialog()), previewWidget);
|
|
}
|
|
|
|
QGtk3FileDialogHelper::~QGtk3FileDialogHelper()
|
|
{
|
|
}
|
|
|
|
+GtkImage *QGtk3FileDialogHelper::previewImage() const
|
|
+{
|
|
+ return GTK_IMAGE(previewWidget);
|
|
+}
|
|
+
|
|
bool QGtk3FileDialogHelper::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent)
|
|
{
|
|
_dir.clear();
|
|
@@ -435,6 +412,33 @@ void QGtk3FileDialogHelper::onCurrentFolderChanged(QGtk3FileDialogHelper *dialog
|
|
emit dialog->directoryEntered(dialog->directory());
|
|
}
|
|
|
|
+void QGtk3FileDialogHelper::onUpdatePreview(GtkDialog *gtkDialog, QGtk3FileDialogHelper *helper)
|
|
+{
|
|
+ gchar *filename = gtk_file_chooser_get_preview_filename(GTK_FILE_CHOOSER(gtkDialog));
|
|
+ if (!filename) {
|
|
+ gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(gtkDialog), false);
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ // Don't attempt to open anything which isn't a regular file. If a named pipe,
|
|
+ // this may hang. See https://crbug.com/534754.
|
|
+ QFileInfo fileinfo(filename);
|
|
+ if (!fileinfo.exists() || !fileinfo.isFile()) {
|
|
+ g_free(filename);
|
|
+ gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(gtkDialog), false);
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ // This will preserve the image's aspect ratio.
|
|
+ GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_size(filename, PREVIEW_WIDTH, PREVIEW_HEIGHT, 0);
|
|
+ g_free(filename);
|
|
+ if (pixbuf) {
|
|
+ gtk_image_set_from_pixbuf(helper->previewImage(), pixbuf);
|
|
+ g_object_unref(pixbuf);
|
|
+ }
|
|
+ gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(gtkDialog), pixbuf ? true : false);
|
|
+}
|
|
+
|
|
static GtkFileChooserAction gtkFileChooserAction(const QSharedPointer<QFileDialogOptions> &options)
|
|
{
|
|
switch (options->fileMode()) {
|
|
diff --git a/common/qgtk3dialoghelpers.h b/common/qgtk3dialoghelpers.h
|
|
index c852fd0..d483a64 100644
|
|
--- a/common/qgtk3dialoghelpers.h
|
|
+++ b/common/qgtk3dialoghelpers.h
|
|
@@ -47,6 +47,8 @@
|
|
#include <QtCore/qstring.h>
|
|
#include <qpa/qplatformdialoghelper.h>
|
|
|
|
+typedef struct _GtkWidget GtkWidget;
|
|
+typedef struct _GtkImage GtkImage;
|
|
typedef struct _GtkDialog GtkDialog;
|
|
typedef struct _GtkFileFilter GtkFileFilter;
|
|
|
|
@@ -88,6 +90,8 @@ public:
|
|
QGtk3FileDialogHelper();
|
|
~QGtk3FileDialogHelper();
|
|
|
|
+ GtkImage *previewImage() const;
|
|
+
|
|
bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent) Q_DECL_OVERRIDE;
|
|
void exec() Q_DECL_OVERRIDE;
|
|
void hide() Q_DECL_OVERRIDE;
|
|
@@ -107,6 +111,7 @@ private Q_SLOTS:
|
|
private:
|
|
static void onSelectionChanged(GtkDialog *dialog, QGtk3FileDialogHelper *helper);
|
|
static void onCurrentFolderChanged(QGtk3FileDialogHelper *helper);
|
|
+ static void onUpdatePreview(GtkDialog *dialog, QGtk3FileDialogHelper *helper);
|
|
void applyOptions();
|
|
void setNameFilters(const QStringList &filters);
|
|
|
|
@@ -115,6 +120,7 @@ private:
|
|
QHash<QString, GtkFileFilter*> _filters;
|
|
QHash<GtkFileFilter*, QString> _filterNames;
|
|
QScopedPointer<QGtk3Dialog> d;
|
|
+ GtkWidget *previewWidget;
|
|
};
|
|
|
|
class QGtk3FontDialogHelper : public QPlatformFontDialogHelper
|
|
diff --git a/decoration/decoration.pro b/decoration/decoration.pro
|
|
index 8f7f039..6c3bb05 100644
|
|
--- a/decoration/decoration.pro
|
|
+++ b/decoration/decoration.pro
|
|
@@ -12,8 +12,7 @@ CONFIG += plugin \
|
|
QT += core \
|
|
gui \
|
|
waylandclient-private \
|
|
- widgets \
|
|
- x11extras
|
|
+ widgets
|
|
|
|
LIBS += -lcommon
|
|
|
|
diff --git a/decoration/qgnomeplatformdecoration.cpp b/decoration/qgnomeplatformdecoration.cpp
|
|
index 61c2af9..c8b381c 100644
|
|
--- a/decoration/qgnomeplatformdecoration.cpp
|
|
+++ b/decoration/qgnomeplatformdecoration.cpp
|
|
@@ -46,6 +46,7 @@
|
|
#include <QtGui/QCursor>
|
|
#include <QtGui/QLinearGradient>
|
|
#include <QtGui/QPainter>
|
|
+#include <QtGui/QPainterPath>
|
|
#include <QtGui/QPalette>
|
|
#include <QtGui/QPixmap>
|
|
|
|
diff --git a/theme/qgnomeplatformtheme.cpp b/theme/qgnomeplatformtheme.cpp
|
|
index 70dbf65..3394b3d 100644
|
|
--- a/theme/qgnomeplatformtheme.cpp
|
|
+++ b/theme/qgnomeplatformtheme.cpp
|
|
@@ -23,8 +23,8 @@
|
|
#include "qgtk3dialoghelpers.h"
|
|
|
|
#include <QApplication>
|
|
+#include <QGuiApplication>
|
|
#include <QStyleFactory>
|
|
-#include <QX11Info>
|
|
|
|
#if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON)
|
|
#include <private/qdbustrayicon_p.h>
|
|
@@ -32,7 +32,7 @@
|
|
|
|
QGnomePlatformTheme::QGnomePlatformTheme()
|
|
{
|
|
- if (!QX11Info::isPlatformX11()) {
|
|
+ if (QGuiApplication::platformName() != QStringLiteral("xcb")) {
|
|
if (!qEnvironmentVariableIsSet("QT_WAYLAND_DECORATION"))
|
|
qputenv("QT_WAYLAND_DECORATION", "gnome");
|
|
}
|
|
@@ -68,7 +68,9 @@ const QFont *QGnomePlatformTheme::font(Font type) const
|
|
|
|
const QPalette *QGnomePlatformTheme::palette(Palette type) const
|
|
{
|
|
- return QPlatformTheme::palette(type);
|
|
+ Q_UNUSED(type);
|
|
+
|
|
+ return m_hints->palette();
|
|
}
|
|
|
|
bool QGnomePlatformTheme::usePlatformNativeDialog(QPlatformTheme::DialogType type) const
|
|
diff --git a/theme/theme.pro b/theme/theme.pro
|
|
index a33d3af..8a1cba7 100644
|
|
--- a/theme/theme.pro
|
|
+++ b/theme/theme.pro
|
|
@@ -13,7 +13,6 @@ QT += core-private \
|
|
dbus \
|
|
gui-private \
|
|
theme_support-private \
|
|
- x11extras \
|
|
widgets
|
|
|
|
LIBS += -lcommon
|