1 /* BEGIN_COMMON_COPYRIGHT_HEADER
2  * (c)LGPL2+
3  *
4  * LXQt - a lightweight, Qt based, desktop toolset
5  * https://lxqt.org
6  *
7  * Copyright: 2011 Razor team
8  *            2014 LXQt team
9  * Authors:
10  *   Alexander Sokoloff <sokoloff.a@gmail.com>
11  *   Maciej Płaza <plaza.maciej@gmail.com>
12  *   Kuzma Shapran <kuzma.shapran@gmail.com>
13  *
14  * This program or library is free software; you can redistribute it
15  * and/or modify it under the terms of the GNU Lesser General Public
16  * License as published by the Free Software Foundation; either
17  * version 2.1 of the License, or (at your option) any later version.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22  * Lesser General Public License for more details.
23 
24  * You should have received a copy of the GNU Lesser General
25  * Public License along with this library; if not, write to the
26  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27  * Boston, MA 02110-1301 USA
28  *
29  * END_COMMON_COPYRIGHT_HEADER */
30 
31 
32 #ifndef LXQTTASKBAR_H
33 #define LXQTTASKBAR_H
34 
35 #include "../panel/ilxqtpanel.h"
36 #include "../panel/ilxqtpanelplugin.h"
37 #include "lxqttaskbarconfiguration.h"
38 #include "lxqttaskgroup.h"
39 #include "lxqttaskbutton.h"
40 
41 #include <QFrame>
42 #include <QBoxLayout>
43 #include <QMap>
44 #include <lxqt-globalkeys.h>
45 #include "../panel/ilxqtpanel.h"
46 #include <KWindowSystem/KWindowSystem>
47 #include <KWindowSystem/KWindowInfo>
48 #include <KWindowSystem/NETWM>
49 
50 class QSignalMapper;
51 class LXQtTaskButton;
52 class ElidedButtonStyle;
53 
54 namespace LXQt {
55 class GridLayout;
56 }
57 
58 class LXQtTaskBar : public QFrame
59 {
60     Q_OBJECT
61 
62 public:
63     explicit LXQtTaskBar(ILXQtPanelPlugin *plugin, QWidget* parent = nullptr);
64     virtual ~LXQtTaskBar();
65 
66     void realign();
67 
buttonStyle()68     Qt::ToolButtonStyle buttonStyle() const { return mButtonStyle; }
buttonWidth()69     int buttonWidth() const { return mButtonWidth; }
closeOnMiddleClick()70     bool closeOnMiddleClick() const { return mCloseOnMiddleClick; }
raiseOnCurrentDesktop()71     bool raiseOnCurrentDesktop() const { return mRaiseOnCurrentDesktop; }
isShowOnlyOneDesktopTasks()72     bool isShowOnlyOneDesktopTasks() const { return mShowOnlyOneDesktopTasks; }
showDesktopNum()73     int showDesktopNum() const { return mShowDesktopNum; }
isShowOnlyCurrentScreenTasks()74     bool isShowOnlyCurrentScreenTasks() const { return mShowOnlyCurrentScreenTasks; }
isShowOnlyMinimizedTasks()75     bool isShowOnlyMinimizedTasks() const { return mShowOnlyMinimizedTasks; }
isAutoRotate()76     bool isAutoRotate() const { return mAutoRotate; }
isGroupingEnabled()77     bool isGroupingEnabled() const { return mGroupingEnabled; }
isShowGroupOnHover()78     bool isShowGroupOnHover() const { return mShowGroupOnHover; }
isIconByClass()79     bool isIconByClass() const { return mIconByClass; }
wheelEventsAction()80     int wheelEventsAction() const { return mWheelEventsAction; }
wheelDeltaThreshold()81     int wheelDeltaThreshold() const { return mWheelDeltaThreshold; }
panel()82     inline ILXQtPanel * panel() const { return mPlugin->panel(); }
plugin()83     inline ILXQtPanelPlugin * plugin() const { return mPlugin; }
84 
85 public slots:
86     void settingsChanged();
87 
88 signals:
89     void buttonRotationRefreshed(bool autoRotate, ILXQtPanel::Position position);
90     void buttonStyleRefreshed(Qt::ToolButtonStyle buttonStyle);
91     void refreshIconGeometry();
92     void showOnlySettingChanged();
93     void iconByClassChanged();
94     void popupShown(LXQtTaskGroup* sender);
95 
96 protected:
97     virtual void dragEnterEvent(QDragEnterEvent * event);
98     virtual void dragMoveEvent(QDragMoveEvent * event);
99 
100 private slots:
101     void refreshTaskList();
102     void refreshButtonRotation();
103     void refreshPlaceholderVisibility();
104     void groupBecomeEmptySlot();
105     void onWindowChanged(WId window, NET::Properties prop, NET::Properties2 prop2);
106     void onWindowAdded(WId window);
107     void onWindowRemoved(WId window);
108     void registerShortcuts();
109     void shortcutRegistered();
110     void activateTask(int pos);
111 
112 private:
113     typedef QMap<WId, LXQtTaskGroup*> windowMap_t;
114 
115 private:
116     void addWindow(WId window);
117     windowMap_t::iterator removeWindow(windowMap_t::iterator pos);
118     void buttonMove(LXQtTaskGroup * dst, LXQtTaskGroup * src, QPoint const & pos);
119 
120 private:
121     QMap<WId, LXQtTaskGroup*> mKnownWindows; //!< Ids of known windows (mapping to buttons/groups)
122     LXQt::GridLayout *mLayout;
123     QList<GlobalKeyShortcut::Action*> mKeys;
124     QSignalMapper *mSignalMapper;
125 
126     // Settings
127     Qt::ToolButtonStyle mButtonStyle;
128     int mButtonWidth;
129     int mButtonHeight;
130     bool mCloseOnMiddleClick;
131     bool mRaiseOnCurrentDesktop;
132     bool mShowOnlyOneDesktopTasks;
133     int mShowDesktopNum;
134     bool mShowOnlyCurrentScreenTasks;
135     bool mShowOnlyMinimizedTasks;
136     bool mAutoRotate;
137     bool mGroupingEnabled;
138     bool mShowGroupOnHover;
139     bool mUngroupedNextToExisting;
140     bool mIconByClass;
141     int mWheelEventsAction;
142     int mWheelDeltaThreshold;
143 
144     bool acceptWindow(WId window) const;
145     void setButtonStyle(Qt::ToolButtonStyle buttonStyle);
146 
147     void wheelEvent(QWheelEvent* event);
148     void changeEvent(QEvent* event);
149     void resizeEvent(QResizeEvent *event);
150 
151     ILXQtPanelPlugin *mPlugin;
152     QWidget *mPlaceHolder;
153     LeftAlignedTextStyle *mStyle;
154 };
155 
156 #endif // LXQTTASKBAR_H
157