summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--demos/browser/browsermainwindow.cpp1
-rw-r--r--demos/textedit/textedit.cpp1
-rw-r--r--src/corelib/global/qnamespace.h3
-rw-r--r--src/gui/styles/gtksymbols.cpp16
-rw-r--r--src/gui/styles/qcommonstyle.cpp41
-rw-r--r--src/gui/styles/qcommonstyle_p.h1
-rw-r--r--src/gui/styles/qgtkstyle.cpp20
-rw-r--r--src/gui/styles/qstyle.cpp2
-rw-r--r--src/gui/styles/qstyle.h2
-rw-r--r--src/gui/widgets/qtoolbutton.cpp10
-rw-r--r--tests/auto/qtoolbar/tst_qtoolbar.cpp4
-rw-r--r--tools/assistant/tools/assistant/mainwindow.cpp5
12 files changed, 101 insertions, 5 deletions
diff --git a/demos/browser/browsermainwindow.cpp b/demos/browser/browsermainwindow.cpp
index 88abb6a..2a0138c 100644
--- a/demos/browser/browsermainwindow.cpp
+++ b/demos/browser/browsermainwindow.cpp
@@ -81,6 +81,7 @@ BrowserMainWindow::BrowserMainWindow(QWidget *parent, Qt::WindowFlags flags)
, m_stop(0)
, m_reload(0)
{
+ setToolButtonStyle(Qt::ToolButtonSystemDefault);
setAttribute(Qt::WA_DeleteOnClose, true);
statusBar()->setSizeGripEnabled(true);
setupMenu();
diff --git a/demos/textedit/textedit.cpp b/demos/textedit/textedit.cpp
index 5eee855..75a13a5 100644
--- a/demos/textedit/textedit.cpp
+++ b/demos/textedit/textedit.cpp
@@ -75,6 +75,7 @@ const QString rsrcPath = ":/images/win";
TextEdit::TextEdit(QWidget *parent)
: QMainWindow(parent)
{
+ setToolButtonStyle(Qt::ToolButtonSystemDefault);
setupFileActions();
setupEditActions();
setupTextActions();
diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h
index e0584e5..077e4ef 100644
--- a/src/corelib/global/qnamespace.h
+++ b/src/corelib/global/qnamespace.h
@@ -1410,7 +1410,8 @@ public:
ToolButtonIconOnly,
ToolButtonTextOnly,
ToolButtonTextBesideIcon,
- ToolButtonTextUnderIcon
+ ToolButtonTextUnderIcon,
+ ToolButtonSystemDefault
};
enum LayoutDirection {
diff --git a/src/gui/styles/gtksymbols.cpp b/src/gui/styles/gtksymbols.cpp
index f553d27..2b32450 100644
--- a/src/gui/styles/gtksymbols.cpp
+++ b/src/gui/styles/gtksymbols.cpp
@@ -68,6 +68,7 @@
#include <QtGui/QStatusBar>
#include <QtGui/QMenuBar>
#include <QtGui/QToolBar>
+#include <QtGui/QToolButton>
#include <QtGui/QX11Info>
#include <X11/Xlib.h>
@@ -633,6 +634,20 @@ GtkStyle* QGtk::gtkStyle(const QString &path)
return 0;
}
+static void update_toolbar_style(GtkWidget *gtkToolBar, GParamSpec *pspec, gpointer user_data)
+{
+ GtkToolbarStyle toolbar_style = GTK_TOOLBAR_ICONS;
+ g_object_get(gtkToolBar, "toolbar-style", &toolbar_style, NULL);
+ QWidgetList widgets = QApplication::allWidgets();
+ for (int i = 0; i < widgets.size(); ++i) {
+ QWidget *widget = widgets.at(i);
+ if (qobject_cast<QToolButton*>(widget)) {
+ QEvent event(QEvent::StyleChange);
+ QApplication::sendEvent(widget, &event);
+ }
+ }
+}
+
void QGtk::initGtkWidgets()
{
// From gtkmain.c
@@ -679,6 +694,7 @@ void QGtk::initGtkWidgets()
add_widget(QGtk::gtk_spin_button_new((GtkAdjustment*)
(QGtk::gtk_adjustment_new(1, 0, 1, 0, 0, 0)), 0.1, 3));
GtkWidget *toolbar = QGtk::gtk_toolbar_new();
+ g_signal_connect (toolbar, "notify::toolbar-style", G_CALLBACK (update_toolbar_style), toolbar);
QGtk::gtk_toolbar_insert((GtkToolbar*)toolbar, QGtk::gtk_separator_tool_item_new(), -1);
add_widget(toolbar);
init_gtk_treeview();
diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp
index 7b8b75e..29176c3 100644
--- a/src/gui/styles/qcommonstyle.cpp
+++ b/src/gui/styles/qcommonstyle.cpp
@@ -840,6 +840,11 @@ static void drawArrow(const QStyle *style, const QStyleOptionToolButton *toolbut
#ifdef Q_WS_X11 // These functions are used to parse the X11 freedesktop icon spec
+static int kdeVersion()
+{
+ static int kdeVersion = qgetenv("KDE_SESSION_VERSION").toInt();
+ return kdeVersion;
+}
void QCommonStylePrivate::lookupIconTheme() const
{
@@ -858,8 +863,7 @@ void QCommonStylePrivate::lookupIconTheme() const
QFileInfo fileInfo(QLatin1String("/usr/share/icons/default.kde"));
QDir dir(fileInfo.canonicalFilePath());
- int kdeVersion = qgetenv("KDE_SESSION_VERSION").toInt();
- QString kdeDefault = kdeVersion >= 4 ? QString::fromLatin1("oxygen") : QString::fromLatin1("crystalsvg");
+ QString kdeDefault = kdeVersion() >= 4 ? QString::fromLatin1("oxygen") : QString::fromLatin1("crystalsvg");
QString defaultTheme = fileInfo.exists() ? dir.dirName() : kdeDefault;
QSettings settings(QApplicationPrivate::kdeHome() +
QLatin1String("/share/config/kdeglobals"), QSettings::IniFormat);
@@ -997,6 +1001,29 @@ QIcon QCommonStylePrivate::createIcon(const QString &name) const
icon.addPixmap(findIcon(32, name));
return icon;
}
+/*!internal
+
+Checks if you are running KDE and looks up the toolbar
+from the KDE configuration file
+
+*/
+int QCommonStylePrivate::lookupToolButtonStyle() const
+{
+ int result = Qt::ToolButtonIconOnly;
+ if (kdeVersion() >= 4) {
+ QSettings settings(QApplicationPrivate::kdeHome() +
+ QLatin1String("/share/config/kdeglobals"), QSettings::IniFormat);
+ settings.beginGroup(QLatin1String("Toolbar style"));
+ QString toolbarStyle = settings.value(QLatin1String("ToolButtonStyle"), QLatin1String("TextBesideIcon")).toString();
+ if (toolbarStyle == QLatin1String("TextBesideIcon"))
+ result = Qt::ToolButtonTextBesideIcon;
+ else if (toolbarStyle == QLatin1String("TextOnly"))
+ result = Qt::ToolButtonTextOnly;
+ else if (toolbarStyle == QLatin1String("TextUnderIcon"))
+ result = Qt::ToolButtonTextUnderIcon;
+ }
+ return result;
+}
#endif //Q_WS_X11
@@ -5290,6 +5317,16 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget
case SH_DockWidget_ButtonsHaveFrame:
ret = true;
break;
+ case SH_ToolButtonStyle:
+ ret = Qt::ToolButtonIconOnly;
+#ifdef Q_WS_X11
+ {
+ Q_D(const QCommonStyle);
+ static int buttonStyle = d->lookupToolButtonStyle();
+ return buttonStyle;
+ }
+#endif
+ break;
default:
ret = 0;
break;
diff --git a/src/gui/styles/qcommonstyle_p.h b/src/gui/styles/qcommonstyle_p.h
index 27ebc05..f2af5b2 100644
--- a/src/gui/styles/qcommonstyle_p.h
+++ b/src/gui/styles/qcommonstyle_p.h
@@ -126,6 +126,7 @@ public:
//icon detection on X11
#ifdef Q_WS_X11
void lookupIconTheme() const;
+ int lookupToolButtonStyle() const;
QIcon createIcon(const QString &) const;
QPixmap findIcon(int size, const QString &) const;
QPixmap findIconHelper(int size, const QString &, const QString &, QStringList &visited) const;
diff --git a/src/gui/styles/qgtkstyle.cpp b/src/gui/styles/qgtkstyle.cpp
index 9d5a3bc..b6ef4c9 100644
--- a/src/gui/styles/qgtkstyle.cpp
+++ b/src/gui/styles/qgtkstyle.cpp
@@ -599,6 +599,26 @@ int QGtkStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidg
break;
+ case SH_ToolButtonStyle:
+ {
+ if (QGtk::isKDE4Session())
+ return QCleanlooksStyle::styleHint(hint, option, widget, returnData);
+ GtkWidget *gtkToolbar = QGtk::gtkWidget(QLS("GtkToolbar"));
+ GtkToolbarStyle toolbar_style = GTK_TOOLBAR_ICONS;
+ g_object_get(gtkToolbar, "toolbar-style", &toolbar_style, NULL);
+ switch (toolbar_style) {
+ case GTK_TOOLBAR_TEXT:
+ return Qt::ToolButtonTextOnly;
+ case GTK_TOOLBAR_BOTH:
+ return Qt::ToolButtonTextUnderIcon;
+ case GTK_TOOLBAR_BOTH_HORIZ:
+ return Qt::ToolButtonTextBesideIcon;
+ case GTK_TOOLBAR_ICONS:
+ default:
+ return Qt::ToolButtonIconOnly;
+ }
+ }
+ break;
case SH_SpinControls_DisableOnBounds:
return int(true);
diff --git a/src/gui/styles/qstyle.cpp b/src/gui/styles/qstyle.cpp
index 797886c..bccd766 100644
--- a/src/gui/styles/qstyle.cpp
+++ b/src/gui/styles/qstyle.cpp
@@ -1865,6 +1865,8 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment,
\value SH_DockWidget_ButtonsHaveFrame Determines if dockwidget buttons should have frames. Default is true.
+ \value SH_ToolButtonStyle Determines the default system style for tool buttons that uses Qt::ToolButtonSystemDefault.
+
\omitvalue SH_UnderlineAccelerator
\sa styleHint()
diff --git a/src/gui/styles/qstyle.h b/src/gui/styles/qstyle.h
index d79c39c..f22bf55 100644
--- a/src/gui/styles/qstyle.h
+++ b/src/gui/styles/qstyle.h
@@ -730,7 +730,7 @@ public:
SH_ItemView_DrawDelegateFrame,
SH_TabBar_CloseButtonPosition,
SH_DockWidget_ButtonsHaveFrame,
-
+ SH_ToolButtonStyle,
// Add new style hint values here
#ifdef QT3_SUPPORT
diff --git a/src/gui/widgets/qtoolbutton.cpp b/src/gui/widgets/qtoolbutton.cpp
index 6dcbfec..5d0a98a 100644
--- a/src/gui/widgets/qtoolbutton.cpp
+++ b/src/gui/widgets/qtoolbutton.cpp
@@ -378,7 +378,11 @@ void QToolButton::initStyleOption(QStyleOptionToolButton *option) const
if (d->hasMenu())
option->features |= QStyleOptionToolButton::HasMenu;
#endif
- option->toolButtonStyle = d->toolButtonStyle;
+ if (d->toolButtonStyle == Qt::ToolButtonSystemDefault) {
+ option->toolButtonStyle = Qt::ToolButtonStyle(style()->styleHint(QStyle::SH_ToolButtonStyle, option, this));
+ } else
+ option->toolButtonStyle = d->toolButtonStyle;
+
if (d->icon.isNull() && d->arrowType == Qt::NoArrow && !forceNoText) {
if (!d->text.isEmpty())
option->toolButtonStyle = Qt::ToolButtonTextOnly;
@@ -476,6 +480,10 @@ QSize QToolButton::minimumSizeHint() const
The default is Qt::ToolButtonIconOnly.
+ If you want your toolbars to depend on system settings,
+ as is possible in GNOME and KDE desktop environments you should
+ use the ToolButtonSystemDefault.
+
QToolButton automatically connects this slot to the relevant
signal in the QMainWindow in which is resides.
*/
diff --git a/tests/auto/qtoolbar/tst_qtoolbar.cpp b/tests/auto/qtoolbar/tst_qtoolbar.cpp
index a762cba..002ea04 100644
--- a/tests/auto/qtoolbar/tst_qtoolbar.cpp
+++ b/tests/auto/qtoolbar/tst_qtoolbar.cpp
@@ -796,6 +796,10 @@ void tst_QToolBar::toolButtonStyle()
tb.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonTextUnderIcon);
QCOMPARE(spy.count(), 0);
+
+ tb.setToolButtonStyle(Qt::ToolButtonSystemDefault);
+ QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonSystemDefault);
+ QCOMPARE(spy.count(), 1);
}
{
diff --git a/tools/assistant/tools/assistant/mainwindow.cpp b/tools/assistant/tools/assistant/mainwindow.cpp
index 617ac4d..ae3f7bc 100644
--- a/tools/assistant/tools/assistant/mainwindow.cpp
+++ b/tools/assistant/tools/assistant/mainwindow.cpp
@@ -93,6 +93,8 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent)
, m_qtDocInstaller(0)
, m_connectedInitSignals(false)
{
+ setToolButtonStyle(Qt::ToolButtonSystemDefault);
+
if (usesDefaultCollection()) {
MainWindow::collectionFileDirectory(true);
m_helpEngine = new QHelpEngine(MainWindow::defaultHelpCollectionFileName(),
@@ -448,12 +450,14 @@ void MainWindow::setupActions()
menu = menuBar()->addMenu(tr("&Edit"));
m_copyAction = menu->addAction(tr("&Copy selected Text"), m_centralWidget,
SLOT(copySelection()));
+ m_copyAction->setIconText("&Copy");
m_copyAction->setIcon(QIcon(resourcePath + QLatin1String("/editcopy.png")));
m_copyAction->setShortcuts(QKeySequence::Copy);
m_copyAction->setEnabled(false);
m_findAction = menu->addAction(tr("&Find in Text..."), m_centralWidget,
SLOT(showTextSearch()));
+ m_findAction->setIconText("&Find");
m_findAction->setIcon(QIcon(resourcePath + QLatin1String("/find.png")));
m_findAction->setShortcuts(QKeySequence::Find);
@@ -513,6 +517,7 @@ void MainWindow::setupActions()
m_syncAction = menu->addAction(tr("Sync with Table of Contents"), this,
SLOT(syncContents()));
+ m_syncAction->setIconText("Sync");
m_syncAction->setIcon(QIcon(resourcePath + QLatin1String("/synctoc.png")));
menu->addSeparator();