summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2009-11-18 16:11:34 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2009-11-18 16:11:34 (GMT)
commitd9c69ff1ec0d5cf78a2bed411aa226f03f3de1af (patch)
tree725200c59f31473a5310ae9fc31e3fcc63a5b238
parentde8b7a4e69b0c5bb5504fd0930cde290984b0cc7 (diff)
parent5d4f58843bb1c8590986aa710dbea30525578a5f (diff)
downloadQt-d9c69ff1ec0d5cf78a2bed411aa226f03f3de1af.zip
Qt-d9c69ff1ec0d5cf78a2bed411aa226f03f3de1af.tar.gz
Qt-d9c69ff1ec0d5cf78a2bed411aa226f03f3de1af.tar.bz2
Merge branch '4.6' into 4.6-staging
-rw-r--r--src/gui/styles/qcleanlooksstyle.cpp1
-rw-r--r--src/gui/styles/qgtkstyle.cpp32
-rw-r--r--src/gui/styles/qgtkstyle_p.cpp58
-rw-r--r--src/gui/styles/qgtkstyle_p.h19
4 files changed, 66 insertions, 44 deletions
diff --git a/src/gui/styles/qcleanlooksstyle.cpp b/src/gui/styles/qcleanlooksstyle.cpp
index 973e682..b08847d 100644
--- a/src/gui/styles/qcleanlooksstyle.cpp
+++ b/src/gui/styles/qcleanlooksstyle.cpp
@@ -3817,6 +3817,7 @@ QSize QCleanlooksStyle::sizeFromContents(ContentsType type, const QStyleOption *
newSize.setWidth(80);
if (!btn->icon.isNull() && btn->iconSize.height() > 16)
newSize -= QSize(0, 2);
+ newSize += QSize(0, 1);
}
if (const QPushButton *button = qobject_cast<const QPushButton *>(widget)) {
if (qobject_cast<const QDialogButtonBox *>(button->parentWidget())) {
diff --git a/src/gui/styles/qgtkstyle.cpp b/src/gui/styles/qgtkstyle.cpp
index 58aa3b8..5566cc6 100644
--- a/src/gui/styles/qgtkstyle.cpp
+++ b/src/gui/styles/qgtkstyle.cpp
@@ -2521,7 +2521,7 @@ void QGtkStyle::drawControl(ControlElement element,
bool selected = menuItem->state & State_Selected && menuItem->state & State_Enabled;
if (selected) {
- QRect rect = option->rect.adjusted(0, 0, -1, -1);
+ QRect rect = option->rect.adjusted(0, 0, 0, -1);
#ifndef QT_NO_COMBOBOX
if (qobject_cast<const QComboBox*>(widget))
rect = option->rect;
@@ -2628,7 +2628,7 @@ void QGtkStyle::drawControl(ControlElement element,
int pixw = pixmap.width();
int pixh = pixmap.height();
QRect pmr(0, 0, pixw, pixh);
- pmr.moveCenter(vCheckRect.center());
+ pmr.moveCenter(vCheckRect.center() - QPoint(0, 1));
painter->setPen(menuItem->palette.text().color());
if (!ignoreCheckMark && checkable && checked) {
QStyleOption opt = *option;
@@ -2670,8 +2670,8 @@ void QGtkStyle::drawControl(ControlElement element,
menuitem->rect.getRect(&x, &y, &w, &h);
int tab = menuitem->tabWidth;
int xm = windowsItemFrame + checkcol + windowsItemHMargin;
- int xpos = menuitem->rect.x() + xm;
- QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
+ int xpos = menuitem->rect.x() + xm + 1;
+ QRect textRect(xpos, y + windowsItemVMargin - 1, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
QString s = menuitem->text;
@@ -2718,13 +2718,19 @@ void QGtkStyle::drawControl(ControlElement element,
QFontMetrics fm(menuitem->font);
int arrow_size = fm.ascent() + fm.descent() - 2 * gtkMenuItem->style->ythickness;
gfloat arrow_scaling = 0.8;
+ int extra = 0;
+ if (!d->gtk_check_version(2, 16, 0)) {
+ // "arrow-scaling" is actually hardcoded and fails on hardy (see gtk+-2.12/gtkmenuitem.c)
+ // though the current documentation states otherwise
+ d->gtk_widget_style_get(gtkMenuItem, "arrow-scaling", &arrow_scaling, NULL);
+ // in versions < 2.16 ythickness was previously subtracted from the arrow_size
+ extra = 2 * gtkMenuItem->style->ythickness;
+ }
- // "arrow-scaling" is actually hardcoded and fails on hardy (see gtk+-2.12/gtkmenuitem.c)
- // though the current documentation states otherwise
int horizontal_padding;
d->gtk_widget_style_get(gtkMenuItem, "horizontal-padding", &horizontal_padding, NULL);
- const int dim = static_cast<int>(arrow_size * arrow_scaling);
+ const int dim = static_cast<int>(arrow_size * arrow_scaling) + extra;
int xpos = menuItem->rect.left() + menuItem->rect.width() - horizontal_padding - dim;
QRect vSubMenuRect = visualRect(option->direction, menuItem->rect,
QRect(xpos, menuItem->rect.top() +
@@ -3123,7 +3129,7 @@ QSize QGtkStyle::sizeFromContents(ContentsType type, const QStyleOption *option,
case CT_ToolButton:
if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
GtkWidget *gtkButton = d->gtkWidget(QLS("GtkToolButton.GtkButton"));
- newSize = size + QSize(2 * gtkButton->style->xthickness, 1 + 2 * gtkButton->style->ythickness);
+ newSize = size + QSize(2 * gtkButton->style->xthickness, 2 + 2 * gtkButton->style->ythickness);
if (widget && qobject_cast<QToolBar *>(widget->parentWidget())) {
QSize minSize(0, 25);
if (toolbutton->toolButtonStyle != Qt::ToolButtonTextOnly)
@@ -3155,7 +3161,7 @@ QSize QGtkStyle::sizeFromContents(ContentsType type, const QStyleOption *option,
GtkWidget *gtkMenuItem = d->gtkWidget(QLS("GtkMenu.GtkMenuItem"));
GtkStyle* style = gtkMenuItem->style;
- newSize += QSize(textMargin + style->xthickness - 2, style->ythickness - 4);
+ newSize += QSize(textMargin + style->xthickness - 1, style->ythickness - 3);
// Cleanlooks assumes a check column of 20 pixels so we need to
// expand it a bit
@@ -3175,7 +3181,7 @@ QSize QGtkStyle::sizeFromContents(ContentsType type, const QStyleOption *option,
case CT_SpinBox:
// QSpinBox does some nasty things that depends on CT_LineEdit
- newSize = size + QSize(0, -d->gtkWidget(QLS("GtkSpinButton"))->style->ythickness * 2 + 2);
+ newSize = size + QSize(0, -d->gtkWidget(QLS("GtkSpinButton"))->style->ythickness * 2);
break;
case CT_PushButton:
@@ -3208,7 +3214,7 @@ QSize QGtkStyle::sizeFromContents(ContentsType type, const QStyleOption *option,
case CT_LineEdit: {
GtkWidget *gtkEntry = d->gtkWidget(QLS("GtkEntry"));
- newSize = size + QSize(2*gtkEntry->style->xthickness, 2*gtkEntry->style->ythickness);
+ newSize = size + QSize(2*gtkEntry->style->xthickness, 2 + 2*gtkEntry->style->ythickness);
}
break;
@@ -3223,7 +3229,7 @@ QSize QGtkStyle::sizeFromContents(ContentsType type, const QStyleOption *option,
newSize = size + QSize(12 + arrowButtonRect.width() + 2*gtkCombo->style->xthickness, 4 + 2*gtkCombo->style->ythickness);
if (!(widget && qobject_cast<QToolBar *>(widget->parentWidget())))
- newSize += QSize(0, 3);
+ newSize += QSize(0, 2);
}
break;
@@ -3236,7 +3242,7 @@ QSize QGtkStyle::sizeFromContents(ContentsType type, const QStyleOption *option,
if (!tab->icon.isNull())
newSize += QSize(6, 0);
}
- newSize += QSize(1, 0);
+ newSize += QSize(1, 1);
break;
default:
diff --git a/src/gui/styles/qgtkstyle_p.cpp b/src/gui/styles/qgtkstyle_p.cpp
index 62d9197..5f4ebae 100644
--- a/src/gui/styles/qgtkstyle_p.cpp
+++ b/src/gui/styles/qgtkstyle_p.cpp
@@ -204,14 +204,14 @@ typedef int (*x11ErrorHandler)(Display*, XErrorEvent*);
Q_DECLARE_METATYPE(QGtkStylePrivate*);
-static void gtkStyleSetCallback(GtkWidget*, QGtkStylePrivate* stylePrivate)
+static void gtkStyleSetCallback(GtkWidget*)
{
qRegisterMetaType<QGtkStylePrivate *>();
// We have to let this function return and complete the event
// loop to ensure that all gtk widgets have been styled before
// updating
- QMetaObject::invokeMethod(styleScheduler(), "updateTheme", Qt::QueuedConnection, Q_ARG(QGtkStylePrivate*, stylePrivate));
+ QMetaObject::invokeMethod(styleScheduler(), "updateTheme", Qt::QueuedConnection);
}
static void update_toolbar_style(GtkWidget *gtkToolBar, GParamSpec *, gpointer)
@@ -255,10 +255,18 @@ bool QGtkStyleFilter::eventFilter(QObject *obj, QEvent *e)
return QObject::eventFilter(obj, e);
}
+QList<QGtkStylePrivate *> QGtkStylePrivate::instances;
+
QGtkStylePrivate::QGtkStylePrivate()
: QCleanlooksStylePrivate()
, filter(this)
{
+ instances.append(this);
+}
+
+QGtkStylePrivate::~QGtkStylePrivate()
+{
+ instances.removeOne(this);
}
void QGtkStylePrivate::init()
@@ -289,7 +297,7 @@ GtkStyle* QGtkStylePrivate::gtkStyle(const QString &path)
/*! \internal
* Get references to gtk functions after we dynamically load the library.
*/
-void QGtkStylePrivate::resolveGtk()
+void QGtkStylePrivate::resolveGtk() const
{
// enforce the "0" suffix, so we'll open libgtk-x11-2.0.so.0
QLibrary libgtk(QLS("gtk-x11-2.0"), 0, 0);
@@ -417,7 +425,7 @@ void QGtkStylePrivate::resolveGtk()
* Initializes a number of gtk menu widgets.
* The widgets are cached.
*/
-void QGtkStylePrivate::initGtkMenu()
+void QGtkStylePrivate::initGtkMenu() const
{
// Create menubar
GtkWidget *gtkMenuBar = QGtkStylePrivate::gtk_menu_bar_new();
@@ -448,7 +456,7 @@ void QGtkStylePrivate::initGtkMenu()
}
-void QGtkStylePrivate::initGtkTreeview()
+void QGtkStylePrivate::initGtkTreeview() const
{
GtkWidget *gtkTreeView = gtk_tree_view_new();
gtk_tree_view_append_column((GtkTreeView*)gtkTreeView, gtk_tree_view_column_new());
@@ -462,7 +470,7 @@ void QGtkStylePrivate::initGtkTreeview()
* Initializes a number of gtk widgets that we can later on use to determine some of our styles.
* The widgets are cached.
*/
-void QGtkStylePrivate::initGtkWidgets()
+void QGtkStylePrivate::initGtkWidgets() const
{
// From gtkmain.c
uid_t ruid = getuid ();
@@ -513,7 +521,7 @@ void QGtkStylePrivate::initGtkWidgets()
if (!gtkWidgetMap()->contains(QLS("GtkButton"))) {
GtkWidget *gtkButton = QGtkStylePrivate::gtk_button_new();
addWidget(gtkButton);
- g_signal_connect(gtkButton, "style-set", G_CALLBACK(gtkStyleSetCallback), this);
+ g_signal_connect(gtkButton, "style-set", G_CALLBACK(gtkStyleSetCallback), 0);
addWidget(QGtkStylePrivate::gtk_tool_button_new(NULL, NULL));
addWidget(QGtkStylePrivate::gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_NONE));
addWidget(QGtkStylePrivate::gtk_hbutton_box_new());
@@ -617,7 +625,7 @@ bool QGtkStylePrivate::getGConfBool(const QString &key, bool fallback)
return retVal;
}
-QString QGtkStylePrivate::getThemeName() const
+QString QGtkStylePrivate::getThemeName()
{
QString themeName;
// We try to parse the gtkrc file first
@@ -734,7 +742,7 @@ void QGtkStylePrivate::addAllSubWidgets(GtkWidget *widget, gpointer v)
}
// Updates window/windowtext palette based on the indicated gtk widget
-QPalette QGtkStylePrivate::gtkWidgetPalette(const QString &gtkWidgetName)
+QPalette QGtkStylePrivate::gtkWidgetPalette(const QString &gtkWidgetName) const
{
GtkWidget *gtkWidget = QGtkStylePrivate::gtkWidget(gtkWidgetName);
Q_ASSERT(gtkWidget);
@@ -755,7 +763,7 @@ QPalette QGtkStylePrivate::gtkWidgetPalette(const QString &gtkWidgetName)
}
-void QGtkStyleUpdateScheduler::updateTheme( QGtkStylePrivate* stylePrivate )
+void QGtkStyleUpdateScheduler::updateTheme()
{
static QString oldTheme(QLS("qt_not_set"));
QPixmapCache::clear();
@@ -764,20 +772,22 @@ void QGtkStyleUpdateScheduler::updateTheme( QGtkStylePrivate* stylePrivate )
if (QApplication::font() != font)
qApp->setFont(font);
- if (oldTheme != stylePrivate->getThemeName()) {
- oldTheme = stylePrivate->getThemeName();
- QPalette newPalette = qApp->style()->standardPalette();
- QApplicationPrivate::setSystemPalette(newPalette);
- QApplication::setPalette(newPalette);
- stylePrivate->initGtkWidgets();
- stylePrivate->applyCustomPaletteHash();
- QList<QWidget*> widgets = QApplication::allWidgets();
- // Notify all widgets that size metrics might have changed
- foreach (QWidget *widget, widgets) {
- QEvent e(QEvent::StyleChange);
- QApplication::sendEvent(widget, &e);
- }
- }
+ if (oldTheme != QGtkStylePrivate::getThemeName()) {
+ oldTheme = QGtkStylePrivate::getThemeName();
+ QPalette newPalette = qApp->style()->standardPalette();
+ QApplicationPrivate::setSystemPalette(newPalette);
+ QApplication::setPalette(newPalette);
+ if (!QGtkStylePrivate::instances.isEmpty()) {
+ QGtkStylePrivate::instances.last()->initGtkWidgets();
+ QGtkStylePrivate::instances.last()->applyCustomPaletteHash();
+ }
+ QList<QWidget*> widgets = QApplication::allWidgets();
+ // Notify all widgets that size metrics might have changed
+ foreach (QWidget *widget, widgets) {
+ QEvent e(QEvent::StyleChange);
+ QApplication::sendEvent(widget, &e);
+ }
+ }
QIconLoader::instance()->updateSystemTheme();
}
diff --git a/src/gui/styles/qgtkstyle_p.h b/src/gui/styles/qgtkstyle_p.h
index fa16769..f6ab8a3 100644
--- a/src/gui/styles/qgtkstyle_p.h
+++ b/src/gui/styles/qgtkstyle_p.h
@@ -255,16 +255,17 @@ class QGtkStylePrivate : public QCleanlooksStylePrivate
Q_DECLARE_PUBLIC(QGtkStyle)
public:
QGtkStylePrivate();
+ ~QGtkStylePrivate();
QGtkStyleFilter filter;
static GtkWidget* gtkWidget(const QString &path);
static GtkStyle* gtkStyle(const QString &path = QLatin1String("GtkWindow"));
- virtual void resolveGtk();
- virtual void initGtkMenu();
- virtual void initGtkTreeview();
- virtual void initGtkWidgets();
+ virtual void resolveGtk() const;
+ virtual void initGtkMenu() const;
+ virtual void initGtkTreeview() const;
+ virtual void initGtkWidgets() const;
static void cleanupGtkWidgets();
@@ -276,7 +277,7 @@ public:
static bool getGConfBool(const QString &key, bool fallback = 0);
static QString getGConfString(const QString &key, const QString &fallback = QString());
- virtual QString getThemeName() const;
+ static QString getThemeName();
virtual int getSpinboxArrowSize() const;
static void setupGtkFileChooser(GtkWidget* gtkFileChooser, QWidget *parent,
@@ -412,7 +413,7 @@ public:
static Ptr_gnome_icon_lookup_sync gnome_icon_lookup_sync;
static Ptr_gnome_vfs_init gnome_vfs_init;
- virtual QPalette gtkWidgetPalette(const QString &gtkWidgetName);
+ virtual QPalette gtkWidgetPalette(const QString &gtkWidgetName) const;
protected:
typedef QHash<QString, GtkWidget*> WidgetMap;
@@ -434,6 +435,10 @@ protected:
static void addWidget(GtkWidget *widget);
virtual void init();
+
+private:
+ static QList<QGtkStylePrivate *> instances;
+ friend class QGtkStyleUpdateScheduler;
};
// Helper to ensure that we have polished all our gtk widgets
@@ -442,7 +447,7 @@ class QGtkStyleUpdateScheduler : public QObject
{
Q_OBJECT
public slots:
- void updateTheme( QGtkStylePrivate* stylePrivate );
+ void updateTheme();
};
QT_END_NAMESPACE