digiKam
squeezedcombobox.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2008-08-21
7  * Description : a combo box with a width not depending of text
8  * content size
9  *
10  * Copyright (C) 2006-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  * Copyright (C) 2008 by Andi Clemens <andi dot clemens at googlemail dot com>
12  * Copyright (C) 2005 by Tom Albers <tomalbers at kde dot nl>
13  *
14  * This program is free software; you can redistribute it
15  * and/or modify it under the terms of the GNU General
16  * Public License as published by the Free Software Foundation;
17  * either version 2, or (at your option)
18  * any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * ============================================================ */
26 
27 #ifndef DIGIKAM_SQUEEZED_COMBOBOX_H
28 #define DIGIKAM_SQUEEZED_COMBOBOX_H
29 
30 // Qt includes
31 
32 #include <QComboBox>
33 
34 // Local includes
35 
36 #include "digikam_export.h"
37 
38 namespace Digikam
39 {
40 
50 class DIGIKAM_EXPORT SqueezedComboBox : public QComboBox
51 {
52  Q_OBJECT
53 
54 public:
55 
61  explicit SqueezedComboBox(QWidget* const parent = nullptr, const char* name = nullptr);
62 
66  ~SqueezedComboBox() override;
67 
74  bool contains(const QString& text) const;
75 
82  int findOriginalText(const QString& text,
83  Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
84 
94  void insertSqueezedItem(const QString& newItem, int index,
95  const QVariant& userData = QVariant());
96 
105  void insertSqueezedList(const QStringList& newItems, int index);
106 
113  void addSqueezedItem(const QString& newItem,
114  const QVariant& userData = QVariant());
115 
121  void setCurrent(const QString& itemText);
122 
128  QString itemHighlighted() const;
129 
135  QString item(int index) const;
136 
140  QSize sizeHint() const override;
141 
142 private Q_SLOTS:
143 
144  void slotTimeOut();
145  void slotUpdateToolTip(int index);
146 
147 private:
148 
149  void resizeEvent(QResizeEvent*) override;
150  QString squeezeText(const QString& original) const;
151 
153  QString currentText() const;
154  void setCurrentText(const QString& itemText);
155  void insertItem(const QString& text);
156  void insertItem(qint32 index, const QString& text);
157  void insertItem(int index,
158  const QIcon& icon,
159  const QString& text,
160  const QVariant& userData = QVariant());
161  void insertItems(int index, const QStringList& list);
162  void addItem(const QString& text);
163  void addItem(const QIcon& icon,
164  const QString& text,
165  const QVariant& userData = QVariant());
166  void addItems(const QStringList& texts);
167  QString itemText(int index) const;
168 
169 private:
170 
171  class Private;
172  Private* const d;
173 };
174 
175 } // namespace Digikam
176 
177 #endif // DIGIKAM_SQUEEZED_COMBOBOX_H
Definition: squeezedcombobox.h:51
Definition: datefolderview.cpp:43