Warning, file /office/calligra/libs/widgets/KoToolBoxButton.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  * Copyright (c) 2015 Friedrich W. H. Kossebau <kossebau@kde.org>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Library General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2 of the License, or (at your option) any later version.
0008  *
0009  * This library is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012  * Library General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Library General Public License
0015  * along with this library; see the file COPYING.LIB.  If not, write to
0016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018  */
0019 
0020 #include "KoToolBoxButton_p.h"
0021 
0022 #include <KoToolManager.h>
0023 #include <KoIcon.h>
0024 
0025 #include <QIcon>
0026 #include <QPalette>
0027 #include <QApplication>
0028 #include <QKeySequence>
0029 
0030 #include <klocalizedstring.h>
0031 
0032 KoToolBoxButton::KoToolBoxButton(KoToolAction *toolAction, QWidget *parent)
0033     : QToolButton(parent)
0034     , m_toolAction(toolAction)
0035 {
0036     setObjectName(m_toolAction->id());
0037     // ensure same L&F
0038     setCheckable(true);
0039     setAutoRaise(true);
0040     setIcon(QIcon::fromTheme(m_toolAction->iconName()));
0041 
0042     setDataFromToolAction();
0043 
0044     connect(this, SIGNAL(clicked(bool)), m_toolAction, SLOT(trigger()));
0045     connect(m_toolAction, SIGNAL(changed()), SLOT(setDataFromToolAction()));
0046 }
0047 
0048 void KoToolBoxButton::setHighlightColor()
0049 {
0050     QPalette p = qApp->palette();
0051     if (isChecked()) {
0052         QPalette palette_highlight(p);
0053         const QColor &c = p.color(QPalette::Highlight);
0054         palette_highlight.setColor(QPalette::Button, c);
0055         setPalette(palette_highlight);
0056     }
0057     else {
0058         setPalette(p);
0059     }
0060 }
0061 
0062 void KoToolBoxButton::setDataFromToolAction()
0063 {
0064     const QString plainToolTip = m_toolAction->toolTip();
0065     const QKeySequence shortcut = m_toolAction->shortcut();
0066     const QString toolTip =
0067         shortcut.isEmpty() ?
0068             i18nc("@info:tooltip", "%1", plainToolTip) :
0069             i18nc("@info:tooltip %2 is shortcut", "%1 (%2)", plainToolTip,
0070                 shortcut.toString());
0071 
0072     setToolTip(toolTip);
0073 }