| 1 | /* BEGIN_COMMON_COPYRIGHT_HEADER |
| 2 | * (c)LGPL2+ |
| 3 | * |
| 4 | * LXQt - a lightweight, Qt based, desktop toolset |
| 5 | * https://lxqt.org |
| 6 | * |
| 7 | * Copyright: 2010-2011 Razor team |
| 8 | * Authors: |
| 9 | * Alexander Sokoloff <[email protected]> |
| 10 | * |
| 11 | * This program or library is free software; you can redistribute it |
| 12 | * and/or modify it under the terms of the GNU Lesser General Public |
| 13 | * License as published by the Free Software Foundation; either |
| 14 | * version 2.1 of the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This library is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | * Lesser General Public License for more details. |
| 20 | |
| 21 | * You should have received a copy of the GNU Lesser General |
| 22 | * Public License along with this library; if not, write to the |
| 23 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 24 | * Boston, MA 02110-1301 USA |
| 25 | * |
| 26 | * END_COMMON_COPYRIGHT_HEADER */ |
| 27 | |
| 28 | |
| 29 | #ifndef LXQTPANEL_H |
| 30 | #define LXQTPANEL_H |
| 31 | |
| 32 | #include <QFrame> |
| 33 | #include <QString> |
| 34 | #include <QTimer> |
| 35 | #include <QPropertyAnimation> |
| 36 | #include <QPointer> |
| 37 | #include <LXQt/Settings> |
| 38 | #include "ilxqtpanel.h" |
| 39 | #include "lxqtpanelglobals.h" |
| 40 | |
| 41 | #define CFG_KEY_SCREENNAME "screen-name" // also used by LXQtPanelApplication (on Wayland) |
| 42 | |
| 43 | class QMenu; |
| 44 | class Plugin; |
| 45 | class QAbstractItemModel; |
| 46 | |
| 47 | namespace LayerShellQt { |
| 48 | class Window; |
| 49 | } |
| 50 | |
| 51 | namespace LXQt { |
| 52 | class Settings; |
| 53 | class PluginInfo; |
| 54 | } |
| 55 | class LXQtPanelLayout; |
| 56 | class ConfigPanelDialog; |
| 57 | class PanelPluginsModel; |
| 58 | class WindowNotifier; |
| 59 | |
| 60 | /*! \brief The LXQtPanel class provides a single lxqt-panel. All LXQtPanel |
| 61 | * instances should be created and handled by LXQtPanelApplication. In turn, |
| 62 | * all Plugins should be created and handled by LXQtPanels. |
| 63 | * |
| 64 | * LXQtPanel is just the panel, it does not incorporate any functionality. |
| 65 | * Each function of the panel is implemented by Plugins, even the mainmenu |
| 66 | * (plugin-mainmenu) and the taskbar (plugin-taskbar). So the LXQtPanel is |
| 67 | * just the container for several Plugins while the different Plugins |
| 68 | * incorporate the functions of the panel. Without the Plugins, the panel |
| 69 | * is quite useless because it is just a box occupying space on the screen. |
| 70 | * |
| 71 | * LXQtPanel itself is a window (QFrame/QWidget) and this class is mainly |
| 72 | * responsible for handling the size and position of this window on the |
| 73 | * screen(s) as well as the different settings. The handling of the plugins |
| 74 | * is outsourced in PanelPluginsModel and LXQtPanelLayout. PanelPluginsModel |
| 75 | * is responsible for loading/creating and handling the plugins. |
| 76 | * LXQtPanelLayout is inherited from QLayout and set as layout to the |
| 77 | * background of LXQtPanel, so LXQtPanelLayout is responsible for the |
| 78 | * layout of all the Plugins. |
| 79 | * |
| 80 | * \sa LXQtPanelApplication, Plugin, PanelPluginsModel, LXQtPanelLayout. |
| 81 | */ |
| 82 | class LXQT_PANEL_API LXQtPanel : public QFrame, public ILXQtPanel |
| 83 | { |
| 84 | Q_OBJECT |
| 85 | |
| 86 | Q_PROPERTY(QString position READ qssPosition) |
| 87 | |
| 88 | // for configuration dialog |
| 89 | friend class ConfigPanelWidget; |
| 90 | friend class ConfigPluginsWidget; |
| 91 | friend class ConfigPanelDialog; |
| 92 | friend class PanelPluginsModel; |
| 93 | |
| 94 | public: |
| 95 | /** |
| 96 | * @brief Stores how the panel should be aligned. Obviously, this applies |
| 97 | * only if the panel does not occupy 100 % of the available space. If the |
| 98 | * panel is vertical, AlignmentLeft means align to the top border of the |
| 99 | * screen, AlignmentRight means align to the bottom. |
| 100 | */ |
| 101 | enum Alignment { |
| 102 | AlignmentLeft = -1, //!< Align the panel to the left or top |
| 103 | AlignmentCenter = 0, //!< Center the panel |
| 104 | AlignmentRight = 1 //!< Align the panel to the right or bottom |
| 105 | }; |
| 106 | |
| 107 | /** |
| 108 | * @brief Creates and initializes the LXQtPanel. Performs the following |
| 109 | * steps: |
| 110 | * 1. Sets Qt window title, flags, attributes. |
| 111 | * 2. Creates the panel layout. |
| 112 | * 3. Prepares the timers. |
| 113 | * 4. Connects signals and slots. |
| 114 | * 5. Reads the settings for this panel. |
| 115 | * 6. Optionally moves the panel to a valid screen (position-dependent). |
| 116 | * 7. Loads the Plugins. |
| 117 | * 8. Shows the panel, even if it is hidable (but then, starts the timer). |
| 118 | * @param configGroup The name of the panel which is used as identifier |
| 119 | * in the config file. |
| 120 | * @param settings The settings instance of this lxqt panel application. |
| 121 | * @param parent Parent QWidget, can be omitted. |
| 122 | */ |
| 123 | LXQtPanel(const QString &configGroup, LXQt::Settings *settings, QWidget *parent = nullptr); |
| 124 | virtual ~LXQtPanel(); |
| 125 | |
| 126 | /** |
| 127 | * @brief Returns the name of this panel which is also used as identifier |
| 128 | * in the config file. |
| 129 | */ |
| 130 | QString name() { return mConfigGroup; } |
| 131 | |
| 132 | /** |
| 133 | * @brief Reads all the necessary settings from mSettings and stores them |
| 134 | * in local variables. Additionally, calls necessary methods like realign() |
| 135 | * or updateStyleSheet() which need to get called after changing settings. |
| 136 | */ |
| 137 | void readSettings(); |
| 138 | |
| 139 | /** |
| 140 | * @brief Creates and shows the popup menu (right click menu). If a plugin |
| 141 | * is given as parameter, the menu will be divided in two groups: |
| 142 | * plugin-specific options and panel-related options. As these two are |
| 143 | * shown together, this menu has to be created by LXQtPanel. |
| 144 | * @param cursorPos The global cursor pos |
| 145 | * @param plugin The plugin whose menu options will be included in the |
| 146 | * context menu. |
| 147 | */ |
| 148 | void showPopupMenu(const QPoint &cursorPos, Plugin *plugin = nullptr); |
| 149 | |
| 150 | // ILXQtPanel overrides ........ |
| 151 | ILXQtPanel::Position position() const override { return mPosition; } |
| 152 | QRect globalGeometry() const override; |
| 153 | QRect calculatePopupWindowPos(QPoint const & absolutePos, QSize const & windowSize) const override; |
| 154 | QRect calculatePopupWindowPos(const ILXQtPanelPlugin *plugin, const QSize &windowSize) const override; |
| 155 | void willShowWindow(QWidget * w) override; |
| 156 | void pluginFlagsChanged(const ILXQtPanelPlugin * plugin) override; |
| 157 | bool isLocked() const override { return mLockPanel; } |
| 158 | QString screenName() const override { return mScreenName; } |
| 159 | // ........ end of ILXQtPanel overrides |
| 160 | |
| 161 | /** |
| 162 | * @brief Searches for a Plugin in the Plugins-list of this panel. Takes |
| 163 | * an ILXQtPanelPlugin as parameter and returns the corresponding Plugin. |
| 164 | * @param iPlugin ILXQtPanelPlugin that we are looking for. |
| 165 | * @return The corresponding Plugin if it is loaded in this panel, nullptr |
| 166 | * otherwise. |
| 167 | */ |
| 168 | Plugin *findPlugin(const ILXQtPanelPlugin *iPlugin) const; |
| 169 | |
| 170 | // For QSS properties .................. |
| 171 | /** |
| 172 | * @brief Returns the position as string |
| 173 | * |
| 174 | * \sa positionToStr(). |
| 175 | */ |
| 176 | QString qssPosition() const; |
| 177 | |
| 178 | /** |
| 179 | * @brief Checks if this LXQtPanel can be placed at a given position |
| 180 | * on the screen with the given screenNum. The condition for doing so |
| 181 | * is that the panel is not located between two screens. |
| 182 | * |
| 183 | * For example, if position is PositionRight, there should be no screen to |
| 184 | * the right of the given screen. That means that there should be no |
| 185 | * screen whose left border has a higher x-coordinate than the x-coordinate |
| 186 | * of the right border of the given screen. This method iterates over all |
| 187 | * screens and checks these conditions. |
| 188 | * @param screenNum screen index as it is used by QDesktopWidget methods |
| 189 | * @param position position where the panel should be placed |
| 190 | * @return true if this panel can be placed at the given position on the |
| 191 | * given screen. |
| 192 | * |
| 193 | * \sa findAvailableScreen(), mScreenNum, mActualScreenNum. |
| 194 | */ |
| 195 | static bool canPlacedOn(int screenNum, LXQtPanel::Position position); |
| 196 | /** |
| 197 | * @brief Returns a string representation of the given position. This |
| 198 | * string is human-readable and can be used in config files. |
| 199 | * @param position position that should be converted to a string. |
| 200 | * @return the string representation of the given position, i.e. |
| 201 | * "Top", "Left", "Right" or "Bottom". |
| 202 | * |
| 203 | * \sa strToPosition() |
| 204 | */ |
| 205 | static QString positionToStr(ILXQtPanel::Position position); |
| 206 | /** |
| 207 | * @brief Returns an ILXQtPanel::Position from the given string. This can |
| 208 | * be used to retrieve ILXQtPanel::Position values from the config files. |
| 209 | * @param str string that should be converted to ILXQtPanel::Position |
| 210 | * @param defaultValue value that will be returned if the string can not |
| 211 | * be converted to an ILXQtPanel::Position. |
| 212 | * @return ILXQtPanel::Position that was determined from str or |
| 213 | * defaultValue if str could not be converted. |
| 214 | * |
| 215 | * \sa positionToStr() |
| 216 | */ |
| 217 | static ILXQtPanel::Position strToPosition(const QString &str, ILXQtPanel::Position defaultValue); |
| 218 | |
| 219 | // Settings |
| 220 | int iconSize() const override { return mIconSize; } //!< Implement ILXQtPanel::iconSize(). |
| 221 | int lineCount() const override { return mLineCount; } //!< Implement ILXQtPanel::lineCount(). |
| 222 | int panelSize() const { return mPanelSize; } |
| 223 | int length() const { return mLength; } |
| 224 | bool lengthInPercents() const { return mLengthInPercents; } |
| 225 | LXQtPanel::Alignment alignment() const { return mAlignment; } |
| 226 | int screenNum() const { return (mWaylandScreenNum >= 0 ? mWaylandScreenNum : mScreenNum); } |
| 227 | QColor fontColor() const { return mFontColor; } |
| 228 | QColor backgroundColor() const { return mBackgroundColor; } |
| 229 | QString backgroundImage() const { return mBackgroundImage; } |
| 230 | int opacity() const { return mOpacity; } |
| 231 | int reserveSpace() const { return mReserveSpace; } |
| 232 | bool hidable() const { return mHidable; } |
| 233 | bool visibleMargin() const { return mVisibleMargin; } |
| 234 | bool hideOnOverlap() const { return mHideOnOverlap; } |
| 235 | int animationTime() const { return mAnimationTime; } |
| 236 | int showDelay() const { return mShowDelayTimer.interval(); } |
| 237 | QString iconTheme() const; |
| 238 | |
| 239 | /*! |
| 240 | * \brief Checks if a given Plugin is running and has the |
| 241 | * ILXQtPanelPlugin::SingleInstance flag set. |
| 242 | * \param pluginId Plugin Identifier which is the basename of the |
| 243 | * .desktop file that specifies the plugin. |
| 244 | * \return true if the Plugin is running and has the |
| 245 | * ILXQtPanelPlugin::SingleInstance flag set, false otherwise. |
| 246 | */ |
| 247 | bool isPluginSingletonAndRunning(QString const & pluginId) const; |
| 248 | /*! |
| 249 | * \brief Updates the config dialog. Used for updating its icons |
| 250 | * when the panel-specific icon theme changes. |
| 251 | */ |
| 252 | void updateConfigDialog() const; |
| 253 | |
| 254 | public slots: |
| 255 | /** |
| 256 | * @brief Shows the QWidget and makes it visible on all desktops. This |
| 257 | * method is NOT related to showPanel(), hidePanel() and hidePanelWork() |
| 258 | * which handle the LXQt hiding by resizing the panel. |
| 259 | */ |
| 260 | void show(); |
| 261 | /** |
| 262 | * @brief Shows the panel (immediately) after it had been hidden before. |
| 263 | * Stops the QTimer mHideTimer. This it NOT the same as QWidget::show() |
| 264 | * because hiding the panel in LXQt is done by making it very thin. So |
| 265 | * this method in fact restores the original size of the panel. |
| 266 | * \param animate flag for the panel show-up animation disabling (\sa mAnimationTime). |
| 267 | * |
| 268 | * \sa mHidable, mHidden, mHideTimer, hidePanel(), hidePanelWork() |
| 269 | */ |
| 270 | void showPanel(bool animate); |
| 271 | /** |
| 272 | * @brief Hides the panel (delayed) by starting the QTimer mHideTimer. |
| 273 | * When this timer times out, hidePanelWork() will be called. So this |
| 274 | * method is called when the cursor leaves the panel area but the panel |
| 275 | * will be hidden later. |
| 276 | * |
| 277 | * \sa mHidable, mHidden, mHideTimer, showPanel(), hidePanelWork() |
| 278 | */ |
| 279 | void hidePanel(); |
| 280 | /** |
| 281 | * @brief Actually hides the panel. Will be invoked when the QTimer |
| 282 | * mHideTimer times out. That timer will be started by showPanel(). This |
| 283 | * is NOT the same as QWidget::hide() because hiding the panel in LXQt is |
| 284 | * done by making the panel very thin. So this method in fact makes the |
| 285 | * panel very thin while the QWidget stays visible. |
| 286 | * |
| 287 | * \sa mHidable, mHidden, mHideTimer, showPanel(), hidePanel() |
| 288 | */ |
| 289 | void hidePanelWork(); |
| 290 | |
| 291 | // Settings |
| 292 | /** |
| 293 | * @brief All the setter methods are designed similar: |
| 294 | * 1. Check if the given value is different from the current value. If not, |
| 295 | * do not do anything and return. |
| 296 | * 2. Set the value. |
| 297 | * 3. If parameter save is true, call saveSettings(true) to store the |
| 298 | * new settings on the disk. |
| 299 | * 4. If necessary, propagate the new value to child objects, e.g. to |
| 300 | * mLayout. |
| 301 | * 5. If necessary, call update methods like realign() or |
| 302 | * updateStyleSheet(). |
| 303 | * @param value The value that should be set. |
| 304 | * @param save If true, saveSettings(true) will be called. |
| 305 | */ |
| 306 | void setPanelSize(int value, bool save); |
| 307 | void setIconSize(int value, bool save); //!< \sa setPanelSize() |
| 308 | void setLineCount(int value, bool save); //!< \sa setPanelSize() |
| 309 | void setLength(int length, bool inPercents, bool save); //!< \sa setPanelSize() |
| 310 | void setPosition(int screen, ILXQtPanel::Position position, bool save); //!< \sa setPanelSize() |
| 311 | void setAlignment(LXQtPanel::Alignment value, bool save); //!< \sa setPanelSize() |
| 312 | void setFontColor(QColor color, bool save); //!< \sa setPanelSize() |
| 313 | void setBackgroundColor(QColor color, bool save); //!< \sa setPanelSize() |
| 314 | void setBackgroundImage(QString path, bool save); //!< \sa setPanelSize() |
| 315 | void setOpacity(int opacity, bool save); //!< \sa setPanelSize() |
| 316 | void setReserveSpace(bool reserveSpace, bool save); //!< \sa setPanelSize() |
| 317 | void setHidable(bool hidable, bool save); //!< \sa setPanelSize() |
| 318 | void setVisibleMargin(bool visibleMargin, bool save); //!< \sa setPanelSize() |
| 319 | void setHideOnOverlap(bool hideOnOverlap, bool save); |
| 320 | void setAnimationTime(int animationTime, bool save); //!< \sa setPanelSize() |
| 321 | void setShowDelay(int showDelay, bool save); //!< \sa setPanelSize() |
| 322 | void setIconTheme(const QString& iconTheme); |
| 323 | |
| 324 | /** |
| 325 | * @brief Saves the current configuration, i.e. writes the current |
| 326 | * configuration variables to mSettings. |
| 327 | * @param later Determines if the settings are written immediately or |
| 328 | * after a short delay. If later==true, the QTimer mDelaySave is started. |
| 329 | * As soon as this timer times out, saveSettings(false) will be called. If |
| 330 | * later==false, settings will be written. |
| 331 | */ |
| 332 | void saveSettings(bool later=false); |
| 333 | /** |
| 334 | * @brief Checks if the panel can be placed on the current screen at the |
| 335 | * current position. If it can not, it will be moved on another screen |
| 336 | * where the desired position is possible. |
| 337 | */ |
| 338 | void ensureVisible(); |
| 339 | |
| 340 | signals: |
| 341 | /** |
| 342 | * @brief This signal gets emitted whenever this panel receives a |
| 343 | * QEvent::LayoutRequest, i.e. "Widget layout needs to be redone.". |
| 344 | * The PanelPluginsModel will connect this signal to the individual |
| 345 | * plugins so they can realign, too. |
| 346 | */ |
| 347 | void realigned(); |
| 348 | /** |
| 349 | * @brief This signal gets emitted at the end of |
| 350 | * userRequestForDeletion() which in turn gets called when the user |
| 351 | * decides to remove a panel. This signal is used by |
| 352 | * LXQtPanelApplication to get notified whenever an LXQtPanel should |
| 353 | * be removed. |
| 354 | * @param self This LXQtPanel. LXQtPanelApplication will use this |
| 355 | * parameter to identify the LXQtPanel that should be removed. |
| 356 | */ |
| 357 | void deletedByUser(LXQtPanel *self); |
| 358 | /** |
| 359 | * @brief This signal is just a relay signal. The pluginAdded signal |
| 360 | * of the PanelPluginsModel (mPlugins) will be connected to this |
| 361 | * signal. Thereby, we can make this signal of a private member |
| 362 | * available as a public signal. |
| 363 | * Currently, this signal is used by LXQtPanelApplication which |
| 364 | * will further re-emit this signal. |
| 365 | */ |
| 366 | void pluginAdded(); |
| 367 | /** |
| 368 | * @brief This signal is just a relay signal. The pluginRemoved signal |
| 369 | * of the PanelPluginsModel (mPlugins) will be connected to this |
| 370 | * signal. Thereby, we can make this signal of a private member |
| 371 | * available as a public signal. |
| 372 | * Currently, this signal is used by LXQtPanelApplication which |
| 373 | * will further re-emit this signal. |
| 374 | */ |
| 375 | void pluginRemoved(); |
| 376 | |
| 377 | protected: |
| 378 | /** |
| 379 | * @brief Overrides QObject::event(QEvent * e). Some functions of |
| 380 | * the panel will be triggered by these events, e.g. showing/hiding |
| 381 | * the panel or showing the context menu. |
| 382 | * @param event The event that was received. |
| 383 | * @return "QObject::event(QEvent *e) should return true if the event e |
| 384 | * was recognized and processed." This is done by passing the event to |
| 385 | * QFrame::event(QEvent *e) at the end. |
| 386 | */ |
| 387 | bool event(QEvent *event) override; |
| 388 | /** |
| 389 | * @brief Overrides QWidget::showEvent(QShowEvent * event). This |
| 390 | * method is called when a widget (in this case: the LXQtPanel) is |
| 391 | * shown. The call could happen before and after the widget is shown. |
| 392 | * This method is just overridden to get notified when the LXQtPanel |
| 393 | * will be shown. Then, LXQtPanel will call realign(). |
| 394 | * @param event The QShowEvent sent by Qt. |
| 395 | */ |
| 396 | void showEvent(QShowEvent *event) override; |
| 397 | |
| 398 | public slots: |
| 399 | /** |
| 400 | * @brief Shows the ConfigPanelDialog and shows the "Config Panel" |
| 401 | * page, i.e. calls showConfigPanelPage(). If the dialog does not |
| 402 | * exist yet, it will be created before. |
| 403 | * |
| 404 | * The "Configure Panel" button in the context menu of the panel will |
| 405 | * be connected to this slot so this method gets called whenever the |
| 406 | * user clicks that button. |
| 407 | * |
| 408 | * Furthermore, this method will be called by LXQtPanelApplication |
| 409 | * when a new plugin gets added (the LXQtPanel instances are handled |
| 410 | * by LXQtPanelApplication). That is why this method/slot has to be |
| 411 | * public. |
| 412 | */ |
| 413 | void showConfigDialog(); |
| 414 | |
| 415 | private slots: |
| 416 | /** |
| 417 | * @brief Shows the ConfigPanelDialog and shows the "Config Plugins" |
| 418 | * page, i.e. calls showConfigPluginsPage(). If the dialog does not |
| 419 | * exist yet, it will be created before. |
| 420 | * |
| 421 | * The "Manage Widgets" button in the context menu of the panel will |
| 422 | * be connected to this slot so this method gets called whenever the |
| 423 | * user clicks that button. |
| 424 | */ |
| 425 | void showAddPluginDialog(); |
| 426 | /** |
| 427 | * @brief Recalculates the geometry of the panel and reserves the |
| 428 | * window manager strut, i.e. it calls setPanelGeometry() and |
| 429 | * updateWmStrut(). |
| 430 | * Two signals will be connected to this slot: |
| 431 | * 1. QDesktopWidget::workAreaResized(int screen) which will be emitted |
| 432 | * when the work area available (on screen) changes. |
| 433 | * 2. LXQt::Application::themeChanged(), i.e. when the user changes |
| 434 | * the theme. |
| 435 | */ |
| 436 | void realign(); |
| 437 | /** |
| 438 | * @brief Moves a plugin in PanelPluginsModel, i.e. calls |
| 439 | * PanelPluginsModel::movePlugin(Plugin * plugin, QString const & nameAfter). |
| 440 | * LXQtPanelLayout::pluginMoved() will be connected to this slot so |
| 441 | * it gets called whenever a plugin was moved in the layout by the user. |
| 442 | * @param plug |
| 443 | */ |
| 444 | void pluginMoved(Plugin * plug); |
| 445 | /** |
| 446 | * @brief Removes this panel's entries from the config file and emits |
| 447 | * the deletedByUser signal. |
| 448 | * The "Remove Panel" button in the panel's context menu will |
| 449 | * be connected to this slot, so this method will be called whenever |
| 450 | * the user clicks "Remove Panel". |
| 451 | */ |
| 452 | void userRequestForDeletion(); |
| 453 | |
| 454 | private: |
| 455 | /** |
| 456 | * @brief The LXQtPanelLayout of this panel. All the Plugins will be added |
| 457 | * to the UI via this layout. |
| 458 | */ |
| 459 | LXQtPanelLayout* mLayout; |
| 460 | /** |
| 461 | * @brief The LXQt::Settings instance as retrieved from |
| 462 | * LXQtPanelApplication. |
| 463 | */ |
| 464 | LXQt::Settings *mSettings; |
| 465 | /** |
| 466 | * @brief The background widget for the panel. This background widget will |
| 467 | * have the background color or the background image if any of these is |
| 468 | * set. This background widget will have the LXQtPanelLayout mLayout which |
| 469 | * will in turn contain all the Plugins. |
| 470 | */ |
| 471 | QFrame *LXQtPanelWidget; |
| 472 | /** |
| 473 | * @brief The name of the panel which will also be used as an identifier |
| 474 | * for config files. |
| 475 | */ |
| 476 | QString mConfigGroup; |
| 477 | /** |
| 478 | * @brief Pointer to the PanelPluginsModel which will store all the Plugins |
| 479 | * that are loaded. |
| 480 | */ |
| 481 | std::unique_ptr<PanelPluginsModel> mPlugins; |
| 482 | /** |
| 483 | * @brief object for storing info if some standalone window is shown |
| 484 | * (for preventing hide) |
| 485 | */ |
| 486 | std::unique_ptr<WindowNotifier> mStandaloneWindows; |
| 487 | |
| 488 | /** |
| 489 | * @brief Returns the screen index of a screen on which this panel could |
| 490 | * be placed at the given position. If possible, the current screen index |
| 491 | * is preserved. So, if the panel can be placed on the current screen, the |
| 492 | * index of that screen will be returned. |
| 493 | * @param position position at which the panel should be placed. |
| 494 | * @return The current screen index if the panel can be placed on the |
| 495 | * current screen or the screen index of a screen that it can be placed on. |
| 496 | * |
| 497 | * \sa canPlacedOn(), mScreenNum, mActualScreenNum. |
| 498 | */ |
| 499 | int findAvailableScreen(LXQtPanel::Position position); |
| 500 | /** |
| 501 | * @brief Update the window manager struts _NET_WM_PARTIAL_STRUT and |
| 502 | * _NET_WM_STRUT for this widget. "The purpose of struts is to reserve |
| 503 | * space at the borders of the desktop. This is very useful for a |
| 504 | * docking area, a taskbar or a panel, for instance. The Window Manager |
| 505 | * should take this reserved area into account when constraining window |
| 506 | * positions - maximized windows, for example, should not cover that |
| 507 | * area." |
| 508 | * \sa http://standards.freedesktop.org/wm-spec/wm-spec-latest.html#NETWMSTRUT |
| 509 | */ |
| 510 | void updateWmStrut(); |
| 511 | |
| 512 | /** |
| 513 | * @brief Loads the plugins, i.e. creates a new PanelPluginsModel. |
| 514 | * Connects the signals and slots and adds all the plugins to the |
| 515 | * layout. |
| 516 | */ |
| 517 | void loadPlugins(); |
| 518 | |
| 519 | /** |
| 520 | * @brief Calculates and sets the geometry (i.e. the position and the size |
| 521 | * on the screen) of the panel. Considers alignment, position, if the panel |
| 522 | * is hidden and if its geometry should be set with animation. |
| 523 | * \param animate flag if showing/hiding the panel should be animated. |
| 524 | */ |
| 525 | void setPanelGeometry(bool animate = false); |
| 526 | /** |
| 527 | * @brief Sets the contents margins of the panel according to its position |
| 528 | * and hiddenness. All margins are zero for visible panels. |
| 529 | */ |
| 530 | void setMargins(); |
| 531 | /** |
| 532 | * @brief Calculates the height of the panel if it is horizontal or the |
| 533 | * width if the panel is vertical. Considers if the panel is hidden and |
| 534 | * ensures that the result is at least PANEL_MINIMUM_SIZE. |
| 535 | * @return The height/width of the panel. |
| 536 | */ |
| 537 | int getReserveDimension(); |
| 538 | |
| 539 | /** |
| 540 | * @brief Calculates the margins of the layer window under Wayland |
| 541 | * by considering the hidden state of the panel. |
| 542 | * @return The margins of the layer window. |
| 543 | */ |
| 544 | QMargins layerWindowMargins(); |
| 545 | |
| 546 | /** |
| 547 | * @brief Stores the geometry of the non-hidden panel, for use in |
| 548 | * calculatePopupWindowPos() |
| 549 | */ |
| 550 | QRect mGeometry; |
| 551 | /** |
| 552 | * @brief Stores the size of the panel, i.e. the height of a horizontal |
| 553 | * panel or the width of a vertical panel in pixels. If the panel is |
| 554 | * hidden (which is achieved by making the panel very thin), this value |
| 555 | * is unchanged. So this value stores the size of the non-hidden panel. |
| 556 | * |
| 557 | * \sa panelSize(), setPanelSize(). |
| 558 | */ |
| 559 | int mPanelSize; |
| 560 | /** |
| 561 | * @brief Stores the edge length of the panel icons in pixels. |
| 562 | * |
| 563 | * \sa ILXQtPanel::iconSize(), setIconSize(). |
| 564 | */ |
| 565 | int mIconSize; |
| 566 | /** |
| 567 | * @brief Stores the number of lines/rows of the panel. |
| 568 | * |
| 569 | * \sa ILXQtPanel::lineCount(), setLineCount(). |
| 570 | */ |
| 571 | int mLineCount; |
| 572 | |
| 573 | /** |
| 574 | * @brief Stores the length of the panel, i.e. the width of a horizontal |
| 575 | * panel or the height of a vertical panel. The unit of this value is |
| 576 | * determined by mLengthInPercents. |
| 577 | * |
| 578 | * \sa mLengthInPercents |
| 579 | */ |
| 580 | int mLength; |
| 581 | /** |
| 582 | * @brief Stores if mLength is stored in pixels or relative to the |
| 583 | * screen size in percents. If true, the length is stored in percents, |
| 584 | * otherwise in pixels. |
| 585 | * |
| 586 | * \sa mLength |
| 587 | */ |
| 588 | bool mLengthInPercents; |
| 589 | |
| 590 | /** |
| 591 | * @brief Stores how this panel is aligned. The meaning of this value |
| 592 | * differs for horizontal and vertical panels. |
| 593 | * |
| 594 | * \sa Alignment. |
| 595 | */ |
| 596 | Alignment mAlignment; |
| 597 | |
| 598 | /** |
| 599 | * @brief Stores the position where the panel is shown |
| 600 | */ |
| 601 | ILXQtPanel::Position mPosition; |
| 602 | /** |
| 603 | * @brief Returns the index of the screen on which this panel should be |
| 604 | * shown. This is the user configured value which can differ from the |
| 605 | * screen that the panel is actually shown on. If the panel can not be |
| 606 | * shown on the configured screen, LXQtPanel will determine another |
| 607 | * screen. The screen that the panel is actually shown on is stored in |
| 608 | * mActualScreenNum. |
| 609 | * |
| 610 | * @return The index of the screen on which this panel should be shown. |
| 611 | * |
| 612 | * \sa mActualScreenNum, canPlacedOn(), findAvailableScreen(). |
| 613 | */ |
| 614 | int mScreenNum; |
| 615 | /** |
| 616 | * @brief screen that the panel is currently shown at (this could |
| 617 | * differ from mScreenNum). |
| 618 | * |
| 619 | * \sa mScreenNum, canPlacedOn(), findAvailableScreen(). |
| 620 | */ |
| 621 | int mActualScreenNum; |
| 622 | /** |
| 623 | * @brief The Wayland screen number, which is found based on the screen name. |
| 624 | * It can be different from mScreenNum and is not saved to the config file. |
| 625 | * Its initial value is -1, meaning that it is not set yet. |
| 626 | * |
| 627 | * \sa mScreenNum, canPlacedOn(), findAvailableScreen(). |
| 628 | */ |
| 629 | int mWaylandScreenNum; |
| 630 | /** |
| 631 | * @brief The name of the Wayland screen, on which this panel should be |
| 632 | * shown. If the panel cannot be shown on that screen, LXQtPanel will |
| 633 | * determine another screen. The screen that the panel is actually |
| 634 | * shown on is stored in mActualScreenNum. |
| 635 | * |
| 636 | * \sa mScreenNum, mActualScreenNum. |
| 637 | */ |
| 638 | QString mScreenName; |
| 639 | /** |
| 640 | * @brief QTimer for delayed saving of changed settings. In many cases, |
| 641 | * instead of storing changes to disk immediately we start this timer. |
| 642 | * If this timer times out, we store the changes to disk. This has the |
| 643 | * advantage that we can store a couple of changes with only one write to |
| 644 | * disk. |
| 645 | * |
| 646 | * \sa saveSettings() |
| 647 | */ |
| 648 | QTimer mDelaySave; |
| 649 | /** |
| 650 | * @brief Stores if the panel is hidable, i.e. if the panel will be |
| 651 | * hidden after the cursor has left the panel area. |
| 652 | * |
| 653 | * \sa mVisibleMargin, mHidden, mHideTimer, showPanel(), hidePanel(), hidePanelWork() |
| 654 | */ |
| 655 | bool mHidable; |
| 656 | /** |
| 657 | * @brief Stores if the hidable panel should have a visible margin. |
| 658 | * |
| 659 | * \sa mHidable, mHidden, mHideTimer, showPanel(), hidePanel(), hidePanelWork() |
| 660 | */ |
| 661 | bool mVisibleMargin; |
| 662 | /** |
| 663 | * @brief Stores if the panel should hide on overlapping a window. |
| 664 | * |
| 665 | * \sa mHidable, mHidden, mHideTimer, showPanel(), hidePanel(), hidePanelWork() |
| 666 | */ |
| 667 | bool mHideOnOverlap; |
| 668 | /** |
| 669 | * @brief Stores if the panel is currently hidden. |
| 670 | * |
| 671 | * \sa mHidable, mVisibleMargin, mHideTimer, showPanel(), hidePanel(), hidePanelWork() |
| 672 | */ |
| 673 | bool mHidden; |
| 674 | /** |
| 675 | * @brief QTimer for hiding the panel. When the cursor leaves the panel |
| 676 | * area, this timer will be started. After this timer has timed out, the |
| 677 | * panel will actually be hidden. |
| 678 | * |
| 679 | * \sa mHidable, mVisibleMargin, mHidden, showPanel(), hidePanel(), hidePanelWork() |
| 680 | */ |
| 681 | QTimer mHideTimer; |
| 682 | /** |
| 683 | * @brief Stores the duration of auto-hide animation. |
| 684 | * |
| 685 | * \sa mHidden, mHideTimer, showPanel(), hidePanel(), hidePanelWork() |
| 686 | */ |
| 687 | int mAnimationTime; |
| 688 | /** |
| 689 | * @brief The timer used for showing an auto-hiding panel with delay. |
| 690 | * |
| 691 | * \sa showPanel() |
| 692 | */ |
| 693 | QTimer mShowDelayTimer; |
| 694 | |
| 695 | QColor mFontColor; //!< Font color that is used in the style sheet. |
| 696 | QColor mBackgroundColor; //!< Background color that is used in the style sheet. |
| 697 | QString mBackgroundImage; //!< Background image that is used in the style sheet. |
| 698 | /** |
| 699 | * @brief Determines the opacity of the background color. The value |
| 700 | * should be in the range from 0 to 100. This will not affect the opacity |
| 701 | * of a background image. |
| 702 | */ |
| 703 | int mOpacity; |
| 704 | /*! |
| 705 | * \brief Flag if the panel should reserve the space under it as not usable |
| 706 | * for "normal" windows. Usable for not 100% wide/hight or hiddable panels, |
| 707 | * if user wants maximized windows go under the panel. |
| 708 | * |
| 709 | * \sa updateWmStrut() |
| 710 | */ |
| 711 | bool mReserveSpace; |
| 712 | |
| 713 | /** |
| 714 | * @brief Pointer to the current ConfigPanelDialog if there is any. Make |
| 715 | * sure to test this pointer for validity because it is lazily loaded. |
| 716 | */ |
| 717 | QPointer<ConfigPanelDialog> mConfigDialog; |
| 718 | |
| 719 | /** |
| 720 | * @brief The animation used for showing/hiding an auto-hiding panel. |
| 721 | */ |
| 722 | QPropertyAnimation *mAnimation; // on X11 |
| 723 | QVariantAnimation *mWAnimation; // on Wayland |
| 724 | |
| 725 | LayerShellQt::Window *mLayerWindow; |
| 726 | |
| 727 | /** |
| 728 | * @brief Flag for providing the configuration options in panel's context menu |
| 729 | */ |
| 730 | bool mLockPanel; |
| 731 | |
| 732 | /** |
| 733 | * @brief Updates the style sheet for the panel. First, the stylesheet is |
| 734 | * created from the preferences. Then, it is set via |
| 735 | * QWidget::setStyleSheet(). |
| 736 | */ |
| 737 | void updateStyleSheet(); |
| 738 | |
| 739 | /** |
| 740 | * @brief Checks if the panel overlaps a window. |
| 741 | */ |
| 742 | bool isPanelOverlapped() const; |
| 743 | |
| 744 | // settings should be kept private for security |
| 745 | LXQt::Settings *settings() const { return mSettings; } |
| 746 | }; |
| 747 | |
| 748 | |
| 749 | #endif // LXQTPANEL_H |