Warning, file /office/calligra/libs/widgets/KoColorPopupButton.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 project
0002  * Copyright (c) 2013 Jean-Nicolas Artaud <jeannicolasartaud@gmail.com>
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 "KoColorPopupButton.h"
0021 
0022 #include <QResizeEvent>
0023 #include <QStyle>
0024 #include <QStyleOptionToolButton>
0025 
0026 #include "WidgetsDebug.h"
0027 
0028 KoColorPopupButton::KoColorPopupButton(QWidget *parent)
0029     : QToolButton(parent)
0030 {
0031     setToolButtonStyle(Qt::ToolButtonIconOnly);
0032 }
0033 
0034 QSize KoColorPopupButton::sizeHint() const
0035 {
0036     QStyleOptionToolButton opt;
0037     initStyleOption(&opt);
0038 
0039     return style()->sizeFromContents(QStyle::CT_ToolButton, &opt, QSize(16,16), this);
0040 }
0041 
0042 void KoColorPopupButton::resizeEvent(QResizeEvent *e)
0043 {
0044     QStyleOptionToolButton opt;
0045     initStyleOption(&opt);
0046     QSize size = iconSize();
0047 
0048     QSize rect = style()->sizeFromContents(QStyle::CT_ToolButton, &opt, size, this);
0049     int iconWidth = size.width() - rect.width() + e->size().width();
0050 
0051     if (iconWidth != size.width()) {
0052         size.setWidth(iconWidth);
0053         setIconSize(size);
0054     }
0055     QToolButton::resizeEvent(e);
0056 
0057     emit iconSizeChanged();
0058 }