File indexing completed on 2024-04-21 16:31:54

0001 /**
0002  * SPDX-FileCopyrightText: (C) 2003 Sébastien Laoût <slaout@linux62.org>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef NEWBASKETDIALOG_H
0008 #define NEWBASKETDIALOG_H
0009 
0010 #include <QDialog>
0011 
0012 #include <QListWidget>
0013 #include <QtCore/QMap>
0014 
0015 class KIconButton;
0016 class QLineEdit;
0017 class QMimeData;
0018 class KComboBox;
0019 class QTreeWidgetItem;
0020 
0021 class BasketScene;
0022 
0023 class KColorCombo2;
0024 
0025 /** The class QListWidget allow to drag items. We don't want to, so we disable it.
0026  * This class also unselect the selected item when the user right click an empty space. We don't want to, so we reselect it if that happens.
0027  * @author Sébastien Laoût
0028  */
0029 class SingleSelectionKIconView : public QListWidget
0030 {
0031     Q_OBJECT
0032 public:
0033     explicit SingleSelectionKIconView(QWidget *parent = nullptr);
0034     QMimeData *dragObject();
0035     QListWidgetItem *selectedItem()
0036     {
0037         return m_lastSelected;
0038     }
0039 private Q_SLOTS:
0040     void slotSelectionChanged(QListWidgetItem *cur);
0041 
0042 private:
0043     QListWidgetItem *m_lastSelected;
0044 };
0045 
0046 /** Struct to store default properties of a new basket.
0047  * When the dialog shows up, the @p icon is used, as well as the @p backgroundColor.
0048  * A template is chosen depending on @p freeLayout and @p columnLayout.
0049  * If @p columnLayout is too high, the template with the more columns will be chosen instead.
0050  * If the user change the background color in the dialog, then @p backgroundImage and @p textColor will not be used!
0051  * @author Sébastien Laoût
0052  */
0053 struct NewBasketDefaultProperties {
0054     QString icon;
0055     QString backgroundImage;
0056     QColor backgroundColor;
0057     QColor textColor;
0058     bool freeLayout;
0059     int columnCount;
0060 
0061     NewBasketDefaultProperties();
0062 };
0063 
0064 /** The dialog to create a new basket from a template.
0065  * @author Sébastien Laoût
0066  */
0067 class NewBasketDialog : public QDialog
0068 {
0069     Q_OBJECT
0070 public:
0071     NewBasketDialog(BasketScene *parentBasket, const NewBasketDefaultProperties &defaultProperties, QWidget *parent = nullptr);
0072     ~NewBasketDialog() override;
0073     void ensurePolished();
0074 protected Q_SLOTS:
0075     void slotOk();
0076     void returnPressed();
0077     void manageTemplates();
0078     void nameChanged(const QString &newName);
0079 
0080 private:
0081     int populateBasketsList(QTreeWidgetItem *item, int indent, int index);
0082     NewBasketDefaultProperties m_defaultProperties;
0083     KIconButton *m_icon;
0084     QLineEdit *m_name;
0085     KColorCombo2 *m_backgroundColor;
0086     QListWidget *m_templates;
0087     KComboBox *m_createIn;
0088     QMap<int, BasketScene *> m_basketsMap;
0089     QPushButton *okButton;
0090 };
0091 
0092 #endif // NEWBASKETDIALOG_H