Dictionary tool buttons should not have an icon shifted when checked.

This just looks better, since the dictionary icons don't collide
with the border anymore.
This commit is contained in:
Tvangeste 2011-07-12 11:25:03 +02:00
parent 747526fca8
commit 5404d4213e
4 changed files with 80 additions and 2 deletions

46
gdappstyle.cc Normal file
View file

@ -0,0 +1,46 @@
/* This file is (c) 2011 Tvangeste <i.4m.l33t@yandex.ru>
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
#include "gdappstyle.hh"
#include "dictionarybar.hh"
#include <QWidget>
#include <QToolButton>
#include <QDebug>
GdAppStyle::GdAppStyle(QProxyStyle * parent) : QProxyStyle(parent) {}
int GdAppStyle::pixelMetric ( PixelMetric metric, const QStyleOption * option, const QWidget * widget) const
{
int defaultVal = QProxyStyle::pixelMetric(metric, option, widget);
if ( dictionaryBarButton( widget ) )
{
if ( metric == QStyle::PM_ButtonShiftVertical || metric == QStyle::PM_ButtonShiftHorizontal )
{
if (option ->state & State_Sunken ) {
return defaultVal;
}
if ( option ->state & State_On ) {
// No shift for for the checked tool buttons on the dictionary bar,
// that's why the whole thing with QProxyStyle is neded, to achieve this.
return 0;
}
}
}
return defaultVal;
}
bool GdAppStyle::dictionaryBarButton(const QWidget * widget) const {
if (widget) {
const QWidget * parent = widget->parentWidget();
if ( parent &&
qobject_cast<const DictionaryBar *>( parent ) &&
qobject_cast<const QToolButton *>( widget ) )
return true;
}
return false;
}

28
gdappstyle.hh Normal file
View file

@ -0,0 +1,28 @@
/* This file is (c) 2011 Tvangeste <i.4m.l33t@yandex.ru>
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
#ifndef GDAPPSTYLE_HH
#define GDAPPSTYLE_HH
#include <QProxyStyle>
#include <QStyleOption>
class GdAppStyle : public QProxyStyle
{
Q_OBJECT
public:
explicit GdAppStyle(QProxyStyle *style = 0);
virtual int pixelMetric ( PixelMetric metric, const QStyleOption * option = 0, const QWidget * widget = 0 ) const;
signals:
public slots:
private:
/// is this widget a tool button on the dictionary bar?
bool dictionaryBarButton(const QWidget * widget) const;
};
#endif // GDAPPSTYLE_HH

View file

@ -167,7 +167,8 @@ HEADERS += folding.hh \
dictspanewidget.hh \
maintabwidget.hh \
dprintf.hh \
mainstatusbar.hh
mainstatusbar.hh \
gdappstyle.hh
FORMS += groups.ui \
dictgroupwidget.ui \
mainwindow.ui \
@ -253,7 +254,8 @@ SOURCES += folding.cc \
programs.cc \
parsecmdline.cc \
maintabwidget.cc \
mainstatusbar.cc
mainstatusbar.cc \
gdappstyle.cc
win32 {
SOURCES += mouseover_win32/ThTypes.c
HEADERS += mouseover_win32/ThTypes.h

View file

@ -3,6 +3,7 @@
#include <stdio.h>
#include <QIcon>
#include "gdappstyle.hh"
#include "mainwindow.hh"
#include "config.hh"
@ -85,6 +86,7 @@ int main( int argc, char ** argv )
app.setApplicationName( "GoldenDict" );
app.setOrganizationDomain( "http://goldendict.org/" );
app.setStyle(new GdAppStyle);
app.setWindowIcon( QIcon( ":/icons/programicon.png" ) );