File indexing completed on 2024-04-14 15:49:46

0001 // SPDX-License-Identifier: GPL-3.0-or-later
0002 /*
0003   Copyright 2018 - 2020 Martin Koller, kollix@aon.at
0004 
0005   This file is part of liquidshell.
0006 
0007   liquidshell is free software: you can redistribute it and/or modify
0008   it under the terms of the GNU General Public License as published by
0009   the Free Software Foundation, either version 3 of the License, or
0010   (at your option) any later version.
0011 
0012   liquidshell is distributed in the hope that it will be useful,
0013   but WITHOUT ANY WARRANTY; without even the implied warranty of
0014   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0015   GNU General Public License for more details.
0016 
0017   You should have received a copy of the GNU General Public License
0018   along with liquidshell.  If not, see <http://www.gnu.org/licenses/>.
0019 */
0020 
0021 #include <IconButton.hxx>
0022 
0023 #include <QHBoxLayout>
0024 
0025 //--------------------------------------------------------------------------------
0026 
0027 IconButton::IconButton(QWidget *parent)
0028   : QToolButton(parent)
0029 {
0030   setAutoRaise(true);
0031   setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
0032 
0033   QHBoxLayout *hbox = new QHBoxLayout(this);
0034 
0035   iconLabel = new QLabel;
0036   iconLabel->setFixedSize(iconSize());
0037   iconLabel->setContextMenuPolicy(Qt::PreventContextMenu);
0038   hbox->addWidget(iconLabel);
0039 
0040   icon2Label = new QLabel;
0041   icon2Label->setFixedSize(iconSize());
0042   icon2Label->setContextMenuPolicy(Qt::PreventContextMenu);
0043   icon2Label->hide();  // until an icon is set
0044   hbox->addWidget(icon2Label);
0045 
0046   textLabel = new QLabel;
0047   hbox->addWidget(textLabel);
0048 }
0049 
0050 //--------------------------------------------------------------------------------
0051 
0052 IconButton::IconButton(QWidget *parent, const QIcon &icon, int theIconSize, const QString &name)
0053   : IconButton(parent)
0054 {
0055   if ( theIconSize != -1 )
0056     setIconSize(QSize(theIconSize, theIconSize));
0057 
0058   iconLabel->setFixedSize(iconSize());
0059   iconLabel->setPixmap(icon.pixmap(iconSize()));
0060 
0061   textLabel->setText(name);
0062 }
0063 
0064 //--------------------------------------------------------------------------------
0065 
0066 void IconButton::setText(const QString &txt)
0067 {
0068   textLabel->setText(txt);
0069 }
0070 
0071 //--------------------------------------------------------------------------------
0072 
0073 void IconButton::setIcon(const QIcon &icon)
0074 {
0075   iconLabel->setPixmap(icon.pixmap(iconSize()));
0076 }
0077 
0078 //--------------------------------------------------------------------------------
0079 
0080 void IconButton::setIcon2(const QIcon &icon)
0081 {
0082   icon2Label->setPixmap(icon.pixmap(iconSize()));
0083   icon2Label->show();
0084 }
0085 
0086 //--------------------------------------------------------------------------------
0087 
0088 QSize IconButton::sizeHint() const
0089 {
0090   return layout()->sizeHint();
0091 }
0092 
0093 //--------------------------------------------------------------------------------