1 /*
2 
3  Copyright (c) 2003-2013 uim Project https://github.com/uim/uim
4 
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without
8  modification, are permitted provided that the following conditions
9  are met:
10 
11  1. Redistributions of source code must retain the above copyright
12     notice, this list of conditions and the following disclaimer.
13  2. Redistributions in binary form must reproduce the above copyright
14     notice, this list of conditions and the following disclaimer in the
15     documentation and/or other materials provided with the distribution.
16  3. Neither the name of authors nor the names of its contributors
17     may be used to endorse or promote products derived from this software
18     without specific prior written permission.
19 
20  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
21  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
24  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  SUCH DAMAGE.
31 
32 */
33 #ifndef UIM_QT4_TOOLBAR_COMMON_UIM_STATE_INDICATOR_H
34 #define UIM_QT4_TOOLBAR_COMMON_UIM_STATE_INDICATOR_H
35 
36 #include <QtCore/QList>
37 #include <QtCore/QMultiHash>
38 #if QT_VERSION < 0x050000
39 # include <QtGui/QMenu>
40 # include <QtGui/QToolButton>
41 # include <QtGui/QFrame>
42 #else
43 # include <QtWidgets/QMenu>
44 # include <QtWidgets/QToolButton>
45 # include <QtWidgets/QFrame>
46 #endif
47 
48 #include <uim/uim.h>
49 #include <uim/uim-helper.h>
50 
51 const int BUTTON_SIZE = 26;
52 const int ICON_SIZE = 16;
53 
54 class QHelperToolbarButton;
55 class QHelperPopupMenu;
56 
57 class QHBoxLayout;
58 
59 class UimStateIndicator : public QFrame
60 {
61     Q_OBJECT
62 
63 public:
64     explicit UimStateIndicator( QWidget *parent = 0 );
65     ~UimStateIndicator();
66 
67     int getNumButtons();
68 
69 protected:
70     void checkHelperConnection();
71 
72     void parseHelperStr( const QString& str );
73     void propListUpdate( const QStringList& lines );
74 
75     static void helper_disconnect_cb();
76 
77 signals:
78     void indicatorResized();
79     void menuRequested( QMenu *menu );
80 
81 public slots:
82     void slotStdinActivated();
83 
84 private slots:
85     void slotPopupMenuAboutToShow();
86     void slotPopupMenuAboutToHide();
87 
88 protected:
89     QList<QHelperToolbarButton *> buttons;
90     bool popupMenuShowing;
91 
92 private:
93     void clearButtons();
94 
95     QHBoxLayout *m_layout;
96     QHash<int, QAction*> actionHash;
97 };
98 
99 class QHelperToolbarButton : public QToolButton
100 {
101     Q_OBJECT
102 public:
103     explicit QHelperToolbarButton( QWidget *parent = 0 );
104 
105     QSize sizeHint() const;
106 
107 signals:
108     void menuRequested( QMenu *menu );
109 
110 private:
111     void mousePressEvent( QMouseEvent *event );
112 };
113 
114 class QHelperPopupMenu : public QMenu
115 {
116     Q_OBJECT
117 
118 public:
119     explicit QHelperPopupMenu( QWidget *parent = 0 );
120     ~QHelperPopupMenu();
121 
122     QAction *insertHelperItem( const QString &indicationIdStr,
123                           const QString &menulabelStr,
124                           const QString &menutooltipStr,
125                           const QString &menucommandStr );
126 
127 public slots:
128     void slotMenuActivated( QAction *action );
129 
130 protected:
131     QMultiHash<QAction *, QString> msgDict;
132 };
133 
134 
135 #endif /* Not def: UIM_QT4_TOOLBAR_COMMON_UIM_STATE_INDICATOR_H */
136