Qt-Advanced-Docking-System/AdvancedDockingSystem/include/ads/SectionWidget.h

113 lines
3.0 KiB
C
Raw Normal View History

2015-12-09 19:21:38 +08:00
#ifndef SECTION_WIDGET_H
#define SECTION_WIDGET_H
#include <QDebug>
#include <QPointer>
2015-12-09 19:21:38 +08:00
#include <QList>
#include <QFrame>
#include <QScrollArea>
class QBoxLayout;
class QStackedLayout;
class QPushButton;
class QMenu;
2015-12-09 19:21:38 +08:00
#include "ads/API.h"
#include "ads/Internal.h"
#include "ads/SectionContent.h"
#include "ads/FloatingWidget.h"
2015-12-09 19:21:38 +08:00
ADS_NAMESPACE_BEGIN
class MainContainerWidget;
2015-12-09 19:21:38 +08:00
class SectionTitleWidget;
class SectionContentWidget;
// SectionWidget manages multiple instances of SectionContent.
// It displays a title TAB, which is clickable and will switch to
// the contents associated to the title when clicked.
class ADS_EXPORT_API SectionWidget : public QFrame
2015-12-09 19:21:38 +08:00
{
Q_OBJECT
friend class MainContainerWidget;
2017-02-08 06:51:29 +08:00
friend class CContainerWidget;
2015-12-09 19:21:38 +08:00
2017-02-08 06:51:29 +08:00
explicit SectionWidget(MainContainerWidget* MainContainer, CContainerWidget* parent);
public:
2015-12-09 19:21:38 +08:00
virtual ~SectionWidget();
int uid() const;
2017-02-08 06:51:29 +08:00
CContainerWidget* containerWidget() const;
2015-12-09 19:21:38 +08:00
QRect titleAreaGeometry() const;
QRect contentAreaGeometry() const;
const QList<SectionContent::RefPtr>& contents() const { return _contents; }
void addContent(const SectionContent::RefPtr& c);
2015-12-09 19:21:38 +08:00
void addContent(const InternalContentData& data, bool autoActivate);
bool takeContent(int uid, InternalContentData& data);
int indexOfContent(const SectionContent::RefPtr& c) const;
int indexOfContentByUid(int uid) const;
int indexOfContentByTitlePos(const QPoint& pos, QWidget* exclude = NULL) const;
int currentIndex() const;
void moveContent(int from, int to);
2015-12-09 19:21:38 +08:00
virtual bool eventFilter(QObject *watched, QEvent *event);
protected:
virtual void showEvent(QShowEvent*);
2015-12-09 19:21:38 +08:00
public slots:
void setCurrentIndex(int index);
private slots:
void onSectionTitleClicked();
void onCloseButtonClicked();
void onTabsMenuActionTriggered(bool);
void updateTabsMenu();
2015-12-09 19:21:38 +08:00
private:
const int _uid;
2017-02-08 06:51:29 +08:00
QPointer<CContainerWidget> m_ContainerWidget;
QPointer<MainContainerWidget> m_MainContainerWidget;
2015-12-09 19:21:38 +08:00
QList<SectionContent::RefPtr> _contents;
QList<SectionTitleWidget*> _sectionTitles;
QList<SectionContentWidget*> _sectionContents;
QBoxLayout* _topLayout;
QScrollArea* _tabsScrollArea;
QWidget* _tabsContainerWidget;
QBoxLayout* _tabsLayout;
QPushButton* _tabsMenuButton;
QPushButton* _closeButton;
int _tabsLayoutInitCount; // used for calculations on _tabsLayout modification calls.
2015-12-09 19:21:38 +08:00
QStackedLayout *_contentsLayout;
QPoint _mousePressPoint;
SectionContent::RefPtr _mousePressContent;
SectionTitleWidget* _mousePressTitleWidget;
static int GetNextUid();
2015-12-09 19:21:38 +08:00
};
/* Custom scrollable implementation for tabs */
class SectionWidgetTabsScrollArea : public QScrollArea
{
public:
SectionWidgetTabsScrollArea(SectionWidget* sectionWidget, QWidget* parent = NULL);
virtual ~SectionWidgetTabsScrollArea();
protected:
QPoint _dragStartPos;
QPointer<FloatingWidget> _fw;
virtual void wheelEvent(QWheelEvent*);
virtual void mousePressEvent(QMouseEvent* ev);
virtual void mouseMoveEvent(QMouseEvent* ev);
};
2015-12-09 19:21:38 +08:00
ADS_NAMESPACE_END
2016-02-12 14:15:10 +08:00
#endif