File indexing completed on 2024-05-19 04:36:39

0001 /* This file is part of the TikZKit project.
0002  *
0003  * Copyright (C) 2014 Dominik Haumann <dhaumann@kde.org>
0004  *
0005  * This library is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU Library General Public License as published
0007  * by the Free Software Foundation, either version 2 of the License, or
0008  * (at your option) any later version.
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
0013  * GNU 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, see
0017  * <http://www.gnu.org/licenses/>.
0018  */
0019 
0020 #ifndef ICON_COMBOBOX_H
0021 #define ICON_COMBOBOX_H
0022 
0023 #include "tikzui_export.h"
0024 
0025 #include <QComboBox>
0026 
0027 /**
0028  * An icon-only combo box.
0029  *
0030  * The IconComboBox shows icons only in the combo box itself.
0031  * However, the popup still shows the text and icons, exactly like QComboBox.
0032  */
0033 class TIKZKITUI_EXPORT IconComboBox : public QComboBox
0034 {
0035     Q_OBJECT
0036 
0037 public:
0038     /**
0039      * Constructor with optional @p parennt widget.
0040      */
0041     explicit IconComboBox(QWidget *parent = nullptr);
0042 
0043     /**
0044      * Override sizeHint() to return a size without text.
0045      * The size matches the required size of the icons.
0046      */
0047     QSize sizeHint() const override;
0048 
0049     /**
0050      * See sizeHint() for details.
0051      */
0052     QSize minimumSizeHint() const override;
0053 
0054     /**
0055      * Overridden to adapt the width of the popup.
0056      */
0057     void showPopup() override;
0058 
0059 protected:
0060     /**
0061      * Overridden to draw the combo box and icon without text.
0062      */
0063     void paintEvent(QPaintEvent *e) override;
0064 };
0065 
0066 #endif // ICON_COMBOBOX_H