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:
mfreiholz 2016-02-26 09:07:19 +01:00
parent 014fb04daf
commit 74f6ba333f
9 changed files with 65 additions and 31 deletions

View File

@ -118,11 +118,19 @@ private:
bool takeContent(const SectionContent::RefPtr& sc, InternalContentData& data); bool takeContent(const SectionContent::RefPtr& sc, InternalContentData& data);
private slots: private slots:
void onActiveTabChanged();
void onActionToggleSectionContentVisibility(bool visible); void onActionToggleSectionContentVisibility(bool visible);
signals: signals:
void orientationChanged(); 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: private:
QList<SectionWidget*> _sections; QList<SectionWidget*> _sections;
QList<FloatingWidget*> _floatings; QList<FloatingWidget*> _floatings;

View File

@ -48,8 +48,10 @@ IconTitleWidget {
ads--SectionTitleWidget QLabel, SectionTitleWidget QLabel { ads--SectionTitleWidget QLabel, SectionTitleWidget QLabel {
color: #ffffff; color: #ffffff;
background: #7c9eb3;
} }
ads--SectionTitleWidget[activeTab="true"] QLabel, SectionTitleWidget[activeTab="true"] QLabel { ads--SectionTitleWidget[activeTab="true"] QLabel, SectionTitleWidget[activeTab="true"] QLabel {
color: #ffffff; color: #000000;
background: #E7F3F8;
} }

View File

@ -70,6 +70,8 @@ SectionWidget* ContainerWidget::addSectionContent(const SectionContent::RefPtr&
data.content = sc; data.content = sc;
data.titleWidget = new SectionTitleWidget(sc, NULL); data.titleWidget = new SectionTitleWidget(sc, NULL);
data.contentWidget = new SectionContentWidget(sc, NULL); data.contentWidget = new SectionContentWidget(sc, NULL);
QObject::connect(data.titleWidget, &SectionTitleWidget::activeTabChanged, this, &ContainerWidget::onActiveTabChanged);
return dropContent(data, sw, area, false); return dropContent(data, sw, area, false);
} }
@ -1021,6 +1023,16 @@ bool ContainerWidget::takeContent(const SectionContent::RefPtr& sc, InternalCont
return found; 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) void ContainerWidget::onActionToggleSectionContentVisibility(bool visible)
{ {
QAction* a = qobject_cast<QAction*>(sender()); QAction* a = qobject_cast<QAction*>(sender());

View File

@ -13,23 +13,25 @@ IconTitleWidget::IconTitleWidget(const QIcon& icon, const QString& title, QWidge
l->setContentsMargins(0, 0, 0, 0); l->setContentsMargins(0, 0, 0, 0);
setLayout(l); setLayout(l);
// Icon label _iconLabel = new QLabel();
if (icon.isNull()) if (!icon.isNull())
{ _iconLabel->setPixmap(icon.pixmap(16, 16));
// QLabel* titleIcon = new QLabel(); l->addWidget(_iconLabel);
// 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);
}
// Title label _titleLabel = new QLabel();
QLabel* titleText = new QLabel(title); _titleLabel->setText(title);
QFont titleFont = titleText->font(); l->addWidget(_titleLabel, 1);
titleText->setFont(titleFont); }
l->addWidget(titleText, 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();
}
} }

View File

@ -4,16 +4,19 @@
#include <QFrame> #include <QFrame>
class QIcon; class QIcon;
class QString; class QString;
class QLabel;
class IconTitleWidget : public QFrame class IconTitleWidget : public QFrame
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit IconTitleWidget(const QIcon& icon, const QString& title, QWidget *parent = 0); explicit IconTitleWidget(const QIcon& icon, const QString& title, QWidget *parent = 0);
void polishUpdate();
signals: public:
QLabel* _iconLabel;
public slots: QLabel* _titleLabel;
}; };
#endif // ICONTITLEWIDGET_H #endif // ICONTITLEWIDGET_H

View File

@ -12,8 +12,8 @@ int main(int argc, char *argv[])
//Q_INIT_RESOURCE(ads); //Q_INIT_RESOURCE(ads);
// Load style sheet // Load style sheet
QFile f(":/stylesheets/default-windows.css"); // QFile f(":/stylesheets/default-windows.css");
// QFile f(":/stylesheets/vendor-partsolutions.css"); QFile f(":/stylesheets/vendor-partsolutions.css");
if (f.open(QFile::ReadOnly)) if (f.open(QFile::ReadOnly))
{ {
QByteArray ba = f.readAll(); QByteArray ba = f.readAll();

View File

@ -9,9 +9,7 @@
#include <QTreeView> #include <QTreeView>
#include <QFileSystemModel> #include <QFileSystemModel>
#include "ads/ContainerWidget.h"
#include "ads/SectionWidget.h" #include "ads/SectionWidget.h"
#include "ads/SectionContent.h"
#include "icontitlewidget.h" #include "icontitlewidget.h"
@ -95,6 +93,7 @@ MainWindow::MainWindow(QWidget *parent) :
_container = new ADS_NS::ContainerWidget(); _container = new ADS_NS::ContainerWidget();
_container->setOrientation(Qt::Vertical); _container->setOrientation(Qt::Vertical);
QObject::connect(_container, &ADS_NS::ContainerWidget::activeTabChanged, this, &MainWindow::onActiveTabChanged);
setCentralWidget(_container); setCentralWidget(_container);
// Test #1: Use high-level public API // Test #1: Use high-level public API
@ -122,6 +121,15 @@ MainWindow::~MainWindow()
delete ui; 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() void MainWindow::onActionAddSectionContentTriggered()
{ {
return; return;

View File

@ -3,15 +3,13 @@
#include <QMainWindow> #include <QMainWindow>
#include "ads/API.h" #include "ads/API.h"
#include "ads/ContainerWidget.h"
#include "ads/SectionContent.h"
namespace Ui { namespace Ui {
class MainWindow; class MainWindow;
} }
ADS_NAMESPACE_BEGIN
class ContainerWidget;
ADS_NAMESPACE_END
class MainWindow : public QMainWindow class MainWindow : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
@ -21,6 +19,7 @@ public:
virtual ~MainWindow(); virtual ~MainWindow();
private slots: private slots:
void onActiveTabChanged(const ADS_NS::SectionContent::RefPtr& sc, bool active);
void onActionAddSectionContentTriggered(); void onActionAddSectionContentTriggered();
protected: protected:

View File

@ -57,7 +57,7 @@ Items sorted by priority
- [x] Show close button on right corner of SectionWidget. How to safe last section position? - [x] Show close button on right corner of SectionWidget. How to safe last section position?
- [x] Serialize state of `_hiddenSectionContents` - [x] Serialize state of `_hiddenSectionContents`
- [x] Add "title" to SectionContent object, which will be used in visible areas to display contents name. - [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 - [x] Add API function to set an SC as active-tab
- [ ] Use scrolling for SectionWidget tabs? - [ ] Use scrolling for SectionWidget tabs?