/** * @RDE_HEADER@ * TabWidget for new EXCON * $Id$ * $HeadURL$ * $Author$ */ #pragma once #include "lts_base.h" #include "lts_widgets_export.h" #include #include #include namespace LtsWidgets { class LtsDialogHelper; class LtsTabBar; /** * @brief The LtsTabWidget class provides a QTabWidget with enhanced functionality for the Lts Layout System. * This TabWidget can either be a..: * * > Master Tab Widget: is the MenuGroup TabWidget (sums up all LtsDialogs which are in the same MenuGroup), contains Tabs to Secondary Identifier TabWidgets * ..or.. * > Secondary Tab Widget: is the Identifier TabWidget, contains all LtsDialogs * */ class LTSWIDGETS_EXPORT LtsTabWidget : public QTabWidget { Q_OBJECT public: /** * @brief LtsTabWidget * @param parent * @param isSecondary true if this is a Secondary TabWidget, false if this is a Master TabWidget */ explicit LtsTabWidget(QWidget *parent = nullptr, bool isSecondary = false); // isSecondary var = last => easy for usage in ui file ~LtsTabWidget(); /** * @brief setActuatorTabStyle decorates the TabBar in a different way (once enabled, it cannot be disabled anymore). * @param enable true to change TabBar decoration. false does nothing. */ void setActuatorTabStyle(bool enable); /** * @brief clearAll removes all Widgets (usually LtsDialogs) from this TabWidget and deletes them. */ void clearAll(); void aboutToClose(); /** * @brief tabBar returns the used LtsTabBar * @return */ LtsTabBar *tabBar(); /** * @brief setTabBar sets the TabBar to an LtsTabBar * @param tabbar the LtsTabBar to replace the current TabBar with. */ void setTabBar(LtsTabBar *tabbar); /** * @brief focusTab focuses the LtsDialog, identified by the Menu and its Identifier, by setting the current Index to the requested LtsDialog's index. * @param menuGroup the menu group of the widget * @param identifier the identifier of the widget * @return true if found & focused - false if not found (so not focused) */ bool focusTab(const QString &menuGroup, const QString &identifier); /** * @brief setSubTabsVisible allows this TabWidget to have SubTabs, so that this TabWidget contains all Tabs refered as the MenuGroups, and the SubTabs * refer to the Identifiers of the LtsDialogs. * DO NOT call this AFTER adding tabs !! * @param visible true if this TabWidget has SubTabs - false if not. */ void setSubTabsVisible(bool visible); /** * @brief getWidget returns the Widget (LtsDialogHelper !!) refered by its MenuGroup and its Identifier from this TabWidget. * @param menuGroup the menu group of the Widget. * @param identifier the identifier of the Widget. * @return the Widget if found, nullptr if not found. (LtsDialogHelper) - To get the dialog: ->getDialog() */ QWidget *getWidget(const QString &menuGroup, const QString &identifier); /** * @brief hasUnsavedChanges checks if there are open Dialogs which have unsaved changes and tells the operator if there are * unsaved changes by the "There are unsaved changes"-Dialog. This method only checks until one unsaved dialog was found. * @param tabWidget The Tab Widget to check if it contains unsaved Dialogs. * @return true if there are unsaved changes, false if there are no unsaved Dialogs. */ static bool hasUnsavedChanges(LtsTabWidget *tabWidget); signals: /** * @brief TODO: DOC ! ! signalCheckTabBarVisibility is emitted when it is necessary to check if this TabWidget can be hidden (e.g. when the last Widget * on this TabWidget is closed, which makes this TabWidget useless and can be hidden). */ void signalCheckTabBarVisibility(); public slots: /** Do not use. * @brief addTab adds a Tab to this TabWidget (is called by the 'addTab'-signal of your LtsDialog) * @param menuGroup the menu group in which this widget should be sorted into. * @param identifier the identifier to check if 1. there already is a widget with this Identifier in this group (so this widget * will not be added (because duplicate)), 2. to make this widget findable when calling e.g. getWidget. * @param dialog helper (which contains the LtsDialog) OLD: the LtsDialog (LtsDialog, as its addTab-signal is automatically connected to this addTab-slot in this method) to * be added to this TabWidget * @param setClosable true if this new Tab / Widget should be able to be closed by the user via the Close-Button on the Tab itself ONLY! (does not * prevent this new Tab to be closed by an Close-Button located on this Widget. */ void addTab(const QString &menuGroup, const QString &identifier, QWidget *widget, bool setClosable = true, bool focusNewTab = true); /** * @brief removeWidget removes a Tab from this TabWidget if it's under control of this TabWidget. * @param widget Tab to remove from TabWidget * @return In case of success true, in other case false */ bool removeWidget(QWidget * widget); private slots: /** * @brief onDeleteTab TODO! rm & free * @param index */ //void onDeleteTab(int index); /** TODO: update * @brief onCloseTab removes the Widget (usually LtsDialogs), identified by its index, from this TabWidget and deletes them. * @param index the index to identify the Widget to be removed */ //void onRemoveTab(int index); /** TODO: update * @brief onCloseTab removes the Widget (usually LtsDialogs), identified by its Pointer, from this TabWidget and deletes them. * @param object the pointer to identify the Widget to be removed */ void onRemoveTab(QObject *object); /** * @brief onCheckTabBarVisibility checks if this TabWidget can be hidden (e.g. when the last Widget * on this TabWidget is closed, which makes this TabWidget useless and can be hidden). */ void onCheckTabBarVisibility(); /** * @brief slotTabCloseRequested makes a close request of an LtsDialog, identified by its index, by calling the * reject-method (see LtsDialog::reject). If the Widget on this index is not an LtsDialog, the close-method of the QWidget-class * is called. * @param index the index to identify the Widget to be closed */ void slotTabCloseRequested(int index); void slotCurrentChanged(int newIdx); void slotMaximizeButtonClicked(); private: /** * @brief addWidget adds a widget to this TabWidget (no matter if this is an Master-/SubTab) - is called by the addTab-method. ONLY ADD LTSDIALOG !! * @param fullName MenuGroup + Identifier, as there is no need to differ between Master-/SubTab * @param widget the widget to add * @param setClosable true if this new Tab / Widget should be able to be closed by the user via the Close-Button on the Tab itself ONLY! (does not * prevent this new Tab to be closed by an Close-Button located on this Widget. */ void addWidget(const QString &fullName, QWidget *widget, bool setClosable, bool focusNewTab = true); // only called by addTab (means that the called class is a sub tab widget) /** * @brief getWidget same as getWidget(MenuGroup, Identifier), but only for MasterTabs, as the Tabs are saved with the full name in the Master Tab (MenuGroup + Ident) * @param fullName MenuGroup + Ident * @return widget if found, nullptr if not */ QWidget *getWidget(const QString &fullName); /** * @brief focusWidget only called by focusTab (means that the called class is a sub tab widget) * @param fullName Menu + Ident * @return true = found & focused, false = not found, not focused */ bool focusWidget(const QString &fullName); /** * @brief slotWindowTitleChanged is called by an LtsDialog(Helper) to sync the Dialog's Title with the Title in the TabBar * @param title the title which was set and has to be set in the TabBar */ void slotWindowTitleChanged(const QString &title); void closeRequestTabWidget(LtsTabWidget *tabWidget); QPoint startPos; LtsTabBar *m_tabbar = nullptr; QPalette m_palette; // when this tab contains a second tab.. /* TODO: use LtsTranslatableIdentifier instead of QString */ QMap m_tabMap; // QWidget because a TabWidget can contain more TabWidgets (Main Tab contains Sub Tabs) and a TabWidget can contain LtsDialogs (Sub Tab contains Dialogs) // FIXME: difference ?????? bool m_hasSubTabs; bool m_isSecondary; QByteArray m_mainSplitterState; }; class CloseButton : public QAbstractButton { Q_OBJECT public: using QAbstractButton::QAbstractButton; void setFontColor(const QColor &fontColor) { m_fontColor = fontColor; } QRectF cross() const; QLineF line() const; protected: void mousePressEvent(QMouseEvent *e) override; void mouseReleaseEvent(QMouseEvent *e) override; void paintEvent(QPaintEvent *e) override; QSize sizeHint() const override; private: QColor m_fontColor; bool m_isPressed = false; }; } // namespace LtsWidgets