mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-24 07:21:32 +08:00
Adds activeTabChanged() signal to let API users know about this state
change. It might be use to re-polish style sheets.
This commit is contained in:
parent
014fb04daf
commit
74f6ba333f
@ -118,11 +118,19 @@ private:
|
||||
bool takeContent(const SectionContent::RefPtr& sc, InternalContentData& data);
|
||||
|
||||
private slots:
|
||||
void onActiveTabChanged();
|
||||
void onActionToggleSectionContentVisibility(bool visible);
|
||||
|
||||
signals:
|
||||
void orientationChanged();
|
||||
|
||||
/*!
|
||||
* Emits whenever the "isActiveTab" state of a SectionContent changes.
|
||||
* Whenever the users sets another tab as active, this signal gets invoked
|
||||
* for the old now inactive tab and the new active tab (the order is unspecified).
|
||||
*/
|
||||
void activeTabChanged(const SectionContent::RefPtr& sc, bool active);
|
||||
|
||||
private:
|
||||
QList<SectionWidget*> _sections;
|
||||
QList<FloatingWidget*> _floatings;
|
||||
|
@ -48,8 +48,10 @@ IconTitleWidget {
|
||||
|
||||
ads--SectionTitleWidget QLabel, SectionTitleWidget QLabel {
|
||||
color: #ffffff;
|
||||
background: #7c9eb3;
|
||||
}
|
||||
|
||||
ads--SectionTitleWidget[activeTab="true"] QLabel, SectionTitleWidget[activeTab="true"] QLabel {
|
||||
color: #ffffff;
|
||||
color: #000000;
|
||||
background: #E7F3F8;
|
||||
}
|
@ -70,6 +70,8 @@ SectionWidget* ContainerWidget::addSectionContent(const SectionContent::RefPtr&
|
||||
data.content = sc;
|
||||
data.titleWidget = new SectionTitleWidget(sc, NULL);
|
||||
data.contentWidget = new SectionContentWidget(sc, NULL);
|
||||
QObject::connect(data.titleWidget, &SectionTitleWidget::activeTabChanged, this, &ContainerWidget::onActiveTabChanged);
|
||||
|
||||
return dropContent(data, sw, area, false);
|
||||
}
|
||||
|
||||
@ -1021,6 +1023,16 @@ bool ContainerWidget::takeContent(const SectionContent::RefPtr& sc, InternalCont
|
||||
return found;
|
||||
}
|
||||
|
||||
void ContainerWidget::onActiveTabChanged()
|
||||
{
|
||||
SectionTitleWidget* stw = qobject_cast<SectionTitleWidget*>(sender());
|
||||
if (stw)
|
||||
{
|
||||
qDebug() << "Active tab changed" << stw->_content->uid() << stw->isActiveTab();
|
||||
emit activeTabChanged(stw->_content, stw->isActiveTab());
|
||||
}
|
||||
}
|
||||
|
||||
void ContainerWidget::onActionToggleSectionContentVisibility(bool visible)
|
||||
{
|
||||
QAction* a = qobject_cast<QAction*>(sender());
|
||||
|
@ -13,23 +13,25 @@ IconTitleWidget::IconTitleWidget(const QIcon& icon, const QString& title, QWidge
|
||||
l->setContentsMargins(0, 0, 0, 0);
|
||||
setLayout(l);
|
||||
|
||||
// Icon label
|
||||
if (icon.isNull())
|
||||
{
|
||||
// QLabel* titleIcon = new QLabel();
|
||||
// titleIcon->setPixmap(style()->standardIcon(QStyle::SP_MessageBoxInformation).pixmap(16, 16));
|
||||
// l->addWidget(titleIcon);
|
||||
}
|
||||
else
|
||||
{
|
||||
QLabel* titleIcon = new QLabel();
|
||||
titleIcon->setPixmap(icon.pixmap(16, 16));
|
||||
l->addWidget(titleIcon);
|
||||
}
|
||||
_iconLabel = new QLabel();
|
||||
if (!icon.isNull())
|
||||
_iconLabel->setPixmap(icon.pixmap(16, 16));
|
||||
l->addWidget(_iconLabel);
|
||||
|
||||
// Title label
|
||||
QLabel* titleText = new QLabel(title);
|
||||
QFont titleFont = titleText->font();
|
||||
titleText->setFont(titleFont);
|
||||
l->addWidget(titleText, 1);
|
||||
_titleLabel = new QLabel();
|
||||
_titleLabel->setText(title);
|
||||
l->addWidget(_titleLabel, 1);
|
||||
}
|
||||
|
||||
void IconTitleWidget::polishUpdate()
|
||||
{
|
||||
QList<QWidget*> widgets;
|
||||
widgets.append(_iconLabel);
|
||||
widgets.append(_titleLabel);
|
||||
foreach (QWidget* w, widgets)
|
||||
{
|
||||
w->style()->unpolish(w);
|
||||
w->style()->polish(w);
|
||||
w->update();
|
||||
}
|
||||
}
|
||||
|
@ -4,16 +4,19 @@
|
||||
#include <QFrame>
|
||||
class QIcon;
|
||||
class QString;
|
||||
class QLabel;
|
||||
|
||||
class IconTitleWidget : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit IconTitleWidget(const QIcon& icon, const QString& title, QWidget *parent = 0);
|
||||
void polishUpdate();
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
public:
|
||||
QLabel* _iconLabel;
|
||||
QLabel* _titleLabel;
|
||||
};
|
||||
|
||||
#endif // ICONTITLEWIDGET_H
|
||||
|
@ -12,8 +12,8 @@ int main(int argc, char *argv[])
|
||||
//Q_INIT_RESOURCE(ads);
|
||||
|
||||
// Load style sheet
|
||||
QFile f(":/stylesheets/default-windows.css");
|
||||
// QFile f(":/stylesheets/vendor-partsolutions.css");
|
||||
// QFile f(":/stylesheets/default-windows.css");
|
||||
QFile f(":/stylesheets/vendor-partsolutions.css");
|
||||
if (f.open(QFile::ReadOnly))
|
||||
{
|
||||
QByteArray ba = f.readAll();
|
||||
|
@ -9,9 +9,7 @@
|
||||
#include <QTreeView>
|
||||
#include <QFileSystemModel>
|
||||
|
||||
#include "ads/ContainerWidget.h"
|
||||
#include "ads/SectionWidget.h"
|
||||
#include "ads/SectionContent.h"
|
||||
|
||||
#include "icontitlewidget.h"
|
||||
|
||||
@ -95,6 +93,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
|
||||
_container = new ADS_NS::ContainerWidget();
|
||||
_container->setOrientation(Qt::Vertical);
|
||||
QObject::connect(_container, &ADS_NS::ContainerWidget::activeTabChanged, this, &MainWindow::onActiveTabChanged);
|
||||
setCentralWidget(_container);
|
||||
|
||||
// Test #1: Use high-level public API
|
||||
@ -122,6 +121,15 @@ MainWindow::~MainWindow()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::onActiveTabChanged(const ADS_NS::SectionContent::RefPtr& sc, bool active)
|
||||
{
|
||||
IconTitleWidget* itw = dynamic_cast<IconTitleWidget*>(sc->titleWidget());
|
||||
if (itw)
|
||||
{
|
||||
itw->polishUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onActionAddSectionContentTriggered()
|
||||
{
|
||||
return;
|
||||
|
@ -3,15 +3,13 @@
|
||||
|
||||
#include <QMainWindow>
|
||||
#include "ads/API.h"
|
||||
#include "ads/ContainerWidget.h"
|
||||
#include "ads/SectionContent.h"
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
ADS_NAMESPACE_BEGIN
|
||||
class ContainerWidget;
|
||||
ADS_NAMESPACE_END
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -21,6 +19,7 @@ public:
|
||||
virtual ~MainWindow();
|
||||
|
||||
private slots:
|
||||
void onActiveTabChanged(const ADS_NS::SectionContent::RefPtr& sc, bool active);
|
||||
void onActionAddSectionContentTriggered();
|
||||
|
||||
protected:
|
||||
|
@ -57,7 +57,7 @@ Items sorted by priority
|
||||
- [x] Show close button on right corner of SectionWidget. How to safe last section position?
|
||||
- [x] Serialize state of `_hiddenSectionContents`
|
||||
- [x] Add "title" to SectionContent object, which will be used in visible areas to display contents name.
|
||||
- [ ] It should be possible to catch the "activeTabChanged" signal for EXTERN_API users
|
||||
- [x] It should be possible to catch the "activeTabChanged" signal for EXTERN_API users
|
||||
- [x] Add API function to set an SC as active-tab
|
||||
- [ ] Use scrolling for SectionWidget tabs?
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user