diff --git a/libs/widgetutils/KoGroupButton.cpp b/libs/widgetutils/KoGroupButton.cpp index 5df9dfb551c..e1576d1f27e 100644 --- a/libs/widgetutils/KoGroupButton.cpp +++ b/libs/widgetutils/KoGroupButton.cpp @@ -1,126 +1,138 @@ /* This file is part of the KDE libraries Copyright (C) 2007 Aurélien Gâteau Copyright (C) 2012 Jean-Nicolas Artaud + Copyright (C) 2012 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "KoGroupButton.h" // Qt #include #include #include #include // KDE #include class KoGroupButton::Private { public: Private(const GroupPosition position) : groupPosition(position) {} GroupPosition groupPosition; - QWidget* dialogParent; }; KoGroupButton::KoGroupButton(GroupPosition position, QWidget* parent) -: d(new Private(position)) + : QToolButton(parent), d(new Private(position)) { - d->dialogParent = parent; - - setToolButtonStyle(Qt::ToolButtonIconOnly); - setFocusPolicy(Qt::NoFocus); - setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + // Make the policy closer to QPushButton's default but horizontal shouldn't be Fixed, + // otherwise spacing gets broken + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); } KoGroupButton::~KoGroupButton() { delete d; } void KoGroupButton::setGroupPosition(KoGroupButton::GroupPosition groupPosition) { d->groupPosition = groupPosition; } KoGroupButton::GroupPosition KoGroupButton::groupPosition() const { return d->groupPosition; } void KoGroupButton::paintEvent(QPaintEvent* event) { if (groupPosition() == NoGroup) { QToolButton::paintEvent(event); return; } QStylePainter painter(this); QStyleOptionToolButton opt; initStyleOption(&opt); QStyleOptionToolButton panelOpt = opt; // Panel QRect& panelRect = panelOpt.rect; switch (groupPosition()) { case GroupLeft: panelRect.setWidth(panelRect.width() * 2); break; case GroupCenter: panelRect.setLeft(panelRect.left() - panelRect.width()); panelRect.setWidth(panelRect.width() * 3); break; case GroupRight: panelRect.setLeft(panelRect.left() - panelRect.width()); break; case NoGroup: Q_ASSERT(0); } + if (!isChecked() && !isDown() && !(panelOpt.state & QStyle::State_MouseOver)) { + // Use 'pushed' appearance for all buttons but button that are not really pushed + // have less contrast and is toned down. + panelOpt.state |= (QStyle::State_On | QStyle::State_Sunken); + QPalette panelPal(panelOpt.palette); + QColor c; + c = panelPal.color(QPalette::Button); + c.setAlpha(50); + panelPal.setColor(QPalette::Button, c); + c = panelPal.color(QPalette::Window); + c.setAlpha(50); + panelPal.setColor(QPalette::Window, c); + panelOpt.palette = panelPal; + painter.setOpacity(0.5); + } painter.drawPrimitive(QStyle::PE_PanelButtonTool, panelOpt); + painter.setOpacity(1.0); // Separator - const int y1 = opt.rect.top() + 6; - const int y2 = opt.rect.bottom() - 6; - if (d->groupPosition & GroupRight) { - const int x = opt.rect.left(); - painter.setPen(opt.palette.color(QPalette::Light)); - painter.drawLine(x, y1, x, y2); - } - if (d->groupPosition & GroupLeft) { + //! @todo make specific fixes for styles such as Plastique, Cleanlooks if there's practical no alernative + const int y1 = opt.rect.top() + 1; + const int y2 = opt.rect.bottom() - 1; + painter.setOpacity(0.4); + if (d->groupPosition != GroupRight) { const int x = opt.rect.right(); - painter.setPen(opt.palette.color(QPalette::Mid)); + painter.setPen(opt.palette.color(QPalette::Dark)); painter.drawLine(x, y1, x, y2); } + painter.setOpacity(1.0); // Text painter.drawControl(QStyle::CE_ToolButtonLabel, opt); // Filtering message on tooltip text for CJK to remove accelerators. // Quoting ktoolbar.cpp: // """ // CJK languages use more verbose accelerator marker: they add a Latin // letter in parenthesis, and put accelerator on that. Hence, the default // removal of ampersand only may not be enough there, instead the whole // parenthesis construct should be removed. Provide these filtering i18n // messages so that translators can use Transcript for custom removal. // """ if (!actions().isEmpty()) { QAction* action = actions().first(); setToolTip(i18nc("@info:tooltip of custom triple button", "%1", action->toolTip())); } } #include diff --git a/libs/widgetutils/KoGroupButton.h b/libs/widgetutils/KoGroupButton.h index d5b9398e072..cf5b50eeac5 100644 --- a/libs/widgetutils/KoGroupButton.h +++ b/libs/widgetutils/KoGroupButton.h @@ -1,60 +1,61 @@ /* This file is part of the KDE libraries Copyright (C) 2007 Aurélien Gâteau Copyright (C) 2012 Jean-Nicolas Artaud + Copyright (C) 2012 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KOGROUPBUTTON_H #define KOGROUPBUTTON_H #include "kowidgetutils_export.h" // Qt #include /** * A thin tool button which can be grouped with another and look like one solid * bar: * * ( button1 | button2 ) */ class KOWIDGETUTILS_EXPORT KoGroupButton : public QToolButton { Q_OBJECT Q_ENUMS( GroupPosition ) Q_PROPERTY( GroupPosition groupPosition READ groupPosition WRITE setGroupPosition ) public: enum GroupPosition { NoGroup, GroupLeft, GroupRight, GroupCenter }; explicit KoGroupButton(GroupPosition position, QWidget* parent = 0); virtual ~KoGroupButton(); void setGroupPosition(KoGroupButton::GroupPosition groupPosition); KoGroupButton::GroupPosition groupPosition() const; protected: virtual void paintEvent(QPaintEvent* event); private: class Private; Private *const d; }; #endif /* KOGROUPBUTTON_H */