1 /*******************************************************************************
2 **
3 ** Photivo
4 **
5 ** Copyright (C) 2008 Jos De Laender <jos.de_laender@telenet.be>
6 ** Copyright (C) 2010 Michael Munzert <mail@mm-log.com>
7 ** Copyright (C) 2012 Bernd Schoeler <brjohn@brother-john.net>
8 **
9 ** This file is part of Photivo.
10 **
11 ** Photivo is free software: you can redistribute it and/or modify
12 ** it under the terms of the GNU General Public License version 3
13 ** as published by the Free Software Foundation.
14 **
15 ** Photivo is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ** GNU General Public License for more details.
19 **
20 ** You should have received a copy of the GNU General Public License
21 ** along with Photivo.  If not, see <http://www.gnu.org/licenses/>.
22 **
23 *******************************************************************************/
24 
25 #ifndef PTCHOICE_H
26 #define PTCHOICE_H
27 
28 #include "ptGuiOptions.h"
29 #include "ptWidget.h"
30 #include "ptInfo.h"
31 #include <filters/ptCfgItem.h>
32 
33 #include <QComboBox>
34 #include <QToolButton>
35 
36 //==============================================================================
37 
38 class ptChoice: public ptWidget {
39 Q_OBJECT
40 
41 public:
42   ptChoice(const QWidget*          MainWindow,
43            const QString           ObjectName,
44            const QString           ParentName,
45            const short             HasDefaultValue,
46            const QVariant          Default,
47            const ptGuiOptionsItem* InitialOptions,
48            const QString           ToolTip,
49            const int               TimeOut);
50   ptChoice(const ptCfgItem &ACfgItem, QWidget *AParent);
51   ptChoice(QWidget *AParent);
52   ~ptChoice();
53 
54   /*! Reimplemented from base class.
55       For compatibility with the new GUI structure. Just calls SetValue().
56    */
57   void    setValue(const QVariant &AValue);
58 
59   void    init(const ptCfgItem &ACfgItem);
60 
61   void      SetValue(const QVariant Value, const short BlockSignal = 1);
62   void      AddOrReplaceItem(const QString Text,const QVariant Data);
Count(void)63   int       Count(void) { return m_ComboBox->count(); }
64   void      SetEnabled(const short Enabled);
65   void      Clear(const short WithDefault = 0);
66   void      Show(const short Show);
GetItemData(const int Index)67   QVariant  GetItemData(const int Index) { return m_ComboBox->itemData(Index); }
CurrentText(void)68   QString   CurrentText(void) { return m_ComboBox->currentText(); }
69   void      Reset();
GetName()70   QString   GetName() {return m_SettingsName;}
71 
72 //-------------------------------------
73 
74 protected:
75   bool eventFilter(QObject *obj, QEvent *event);
76 
77 //-------------------------------------
78 
79 private:
80   void createGUI();
81   int  getIdxFromValue(const QVariant &AValue);
82 
83   QVariant m_Value;
84   QVariant m_DefaultValue;
85   short    m_HaveDefault;
86   int      m_TimeOut;
87   const ptGuiOptionsItem* m_InitialOptions;
88   QList<ptCfgItem::TComboEntry> m_InitialOptionsNewschool;
89 
90   QWidget*     m_Parent;
91   QComboBox*   m_ComboBox;
92   QToolButton* m_Button;
93   QTimer*      m_Timer;
94   QString      m_SettingsName;
95 
96 //-------------------------------------
97 
98 signals:
99   void valueChanged(QVariant Value);
100 
101 //-------------------------------------
102 
103 private slots:
104   void OnValueChanged(int Value);
105   void OnButtonClicked();
106   void OnValueChangedTimerExpired();
107 
108 };
109 
110 #endif // PTCHOICE_H
111