Warning, file /office/calligra/libs/widgetutils/KoGroupButton.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE libraries 0002 Copyright (C) 2007 Aurélien Gâteau <agateau@kde.org> 0003 Copyright (C) 2012 Jean-Nicolas Artaud <jeannicolasartaud@gmail.com> 0004 Copyright (C) 2012 Jarosław Staniek <staniek@kde.org> 0005 0006 This library is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU Library General Public 0008 License version 2 as published by the Free Software Foundation. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #include "KoGroupButton.h" 0022 0023 // Qt 0024 #include <QAction> 0025 #include <QStyleOptionToolButton> 0026 #include <QStylePainter> 0027 #include <QToolButton> 0028 0029 // KF5 0030 #include <KLocalizedString> 0031 0032 class Q_DECL_HIDDEN KoGroupButton::Private 0033 { 0034 public: 0035 Private(KoGroupButton *qq, const GroupPosition position) : groupPosition(position) 0036 { 0037 // Make the policy closer to QPushButton's default but horizontal shouldn't be Fixed, 0038 // otherwise spacing gets broken 0039 qq->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); 0040 } 0041 GroupPosition groupPosition; 0042 }; 0043 0044 KoGroupButton::KoGroupButton(GroupPosition position, QWidget* parent) 0045 : QToolButton(parent), d(new Private(this, position)) 0046 { 0047 } 0048 0049 KoGroupButton::KoGroupButton(QWidget* parent) 0050 : QToolButton(parent), d(new Private(this, NoGroup)) 0051 { 0052 } 0053 0054 KoGroupButton::~KoGroupButton() 0055 { 0056 delete d; 0057 } 0058 0059 void KoGroupButton::setGroupPosition(KoGroupButton::GroupPosition groupPosition) 0060 { 0061 d->groupPosition = groupPosition; 0062 } 0063 0064 KoGroupButton::GroupPosition KoGroupButton::groupPosition() const 0065 { 0066 return d->groupPosition; 0067 } 0068 0069 void KoGroupButton::paintEvent(QPaintEvent* event) 0070 { 0071 if (groupPosition() == NoGroup) { 0072 QToolButton::paintEvent(event); 0073 return; 0074 } 0075 QStylePainter painter(this); 0076 QStyleOptionToolButton opt; 0077 initStyleOption(&opt); 0078 QStyleOptionToolButton panelOpt = opt; 0079 0080 // Panel 0081 QRect& panelRect = panelOpt.rect; 0082 switch (groupPosition()) { 0083 case GroupLeft: 0084 panelRect.setWidth(panelRect.width() * 2); 0085 break; 0086 case GroupCenter: 0087 panelRect.setLeft(panelRect.left() - panelRect.width()); 0088 panelRect.setWidth(panelRect.width() * 3); 0089 break; 0090 case GroupRight: 0091 panelRect.setLeft(panelRect.left() - panelRect.width()); 0092 break; 0093 case NoGroup: 0094 Q_ASSERT(0); 0095 } 0096 if (autoRaise()) { 0097 if (!isChecked() && !isDown() && !(panelOpt.state & QStyle::State_MouseOver)) { 0098 // Use 'pushed' appearance for all buttons, but those that are not really pushed 0099 // are drawn with less contrast and are toned down. 0100 panelOpt.state |= (QStyle::State_On | QStyle::State_Sunken); 0101 QPalette panelPal(panelOpt.palette); 0102 QColor c; 0103 c = panelPal.color(QPalette::Button); 0104 c.setAlpha(50); 0105 panelPal.setColor(QPalette::Button, c); 0106 c = panelPal.color(QPalette::Window); 0107 c.setAlpha(50); 0108 panelPal.setColor(QPalette::Window, c); 0109 panelOpt.palette = panelPal; 0110 painter.setOpacity(0.5); 0111 } 0112 } 0113 painter.drawPrimitive(QStyle::PE_PanelButtonTool, panelOpt); 0114 painter.setOpacity(1.0); 0115 0116 // Separator 0117 //! @todo make specific fixes for styles such as Plastique, Cleanlooks if there's practical no alternative 0118 const int y1 = opt.rect.top() + 1; 0119 const int y2 = opt.rect.bottom() - 1; 0120 painter.setOpacity(0.4); 0121 if (d->groupPosition != GroupRight) { 0122 const int x = opt.rect.right(); 0123 painter.setPen(QPen(opt.palette.color(QPalette::Dark), 0)); 0124 painter.drawLine(x, y1, x, y2); 0125 } 0126 painter.setOpacity(1.0); 0127 0128 // Text 0129 painter.drawControl(QStyle::CE_ToolButtonLabel, opt); 0130 0131 // Filtering message on tooltip text for CJK to remove accelerators. 0132 // Quoting ktoolbar.cpp: 0133 // """ 0134 // CJK languages use more verbose accelerator marker: they add a Latin 0135 // letter in parenthesis, and put accelerator on that. Hence, the default 0136 // removal of ampersand only may not be enough there, instead the whole 0137 // parenthesis construct should be removed. Provide these filtering i18n 0138 // messages so that translators can use Transcript for custom removal. 0139 // """ 0140 if (!actions().isEmpty()) { 0141 QAction* action = actions().constFirst(); 0142 setToolTip(i18nc("@info:tooltip of custom triple button", "%1", action->toolTip())); 0143 } 0144 }