From 7d400af1f372990c8264c7e4a606d2ac0d523ef7 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 26 Apr 2013 17:16:56 +0200 Subject: [PATCH] Implement a TaskGroup class to show widgets without extra header --- src/Gui/TaskView/TaskView.cpp | 84 +++++++++++++++++++++++++++-------- src/Gui/TaskView/TaskView.h | 12 +++++ 2 files changed, 77 insertions(+), 19 deletions(-) diff --git a/src/Gui/TaskView/TaskView.cpp b/src/Gui/TaskView/TaskView.cpp index d5f647809..aa52c86e7 100644 --- a/src/Gui/TaskView/TaskView.cpp +++ b/src/Gui/TaskView/TaskView.cpp @@ -61,7 +61,72 @@ TaskWidget::~TaskWidget() { } +//************************************************************************** +//************************************************************************** +// TaskGroup +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +TaskGroup::TaskGroup(QWidget *parent) + : iisTaskGroup(parent, false) +{ + setScheme(iisFreeCADTaskPanelScheme::defaultScheme()); +} + +TaskGroup::~TaskGroup() +{ +} + +namespace Gui { namespace TaskView { +class TaskIconLabel : public iisIconLabel { +public: + TaskIconLabel(const QIcon &icon, + const QString &title, + QWidget *parent = 0) + : iisIconLabel(icon, title, parent) { + // do not allow to get the focus because when hiding the task box + // it could cause to activate another MDI view. + setFocusPolicy(Qt::NoFocus); + } + void setTitle(const QString &text) { + myText = text; + update(); + } +}; +} +} + +void TaskGroup::actionEvent (QActionEvent* e) +{ + QAction *action = e->action(); + switch (e->type()) { + case QEvent::ActionAdded: + { + TaskIconLabel *label = new TaskIconLabel( + action->icon(), action->text(), this); + this->addIconLabel(label); + connect(label,SIGNAL(clicked()),action,SIGNAL(triggered())); + break; + } + case QEvent::ActionChanged: + { + // update label when action changes + QBoxLayout* bl = this->groupLayout(); + int index = this->actions().indexOf(action); + if (index < 0) break; + QWidgetItem* item = static_cast(bl->itemAt(index)); + TaskIconLabel* label = static_cast(item->widget()); + label->setTitle(action->text()); + break; + } + case QEvent::ActionRemoved: + { + // cannot change anything + break; + } + default: + break; + } +} //************************************************************************** //************************************************************************** @@ -125,25 +190,6 @@ void TaskBox::hideGroupBox() setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); } -namespace Gui { namespace TaskView { -class TaskIconLabel : public iisIconLabel { -public: - TaskIconLabel(const QIcon &icon, - const QString &title, - QWidget *parent = 0) - : iisIconLabel(icon, title, parent) { - // do not allow to get the focus because when hiding the task box - // it could cause to activate another MDI view. - setFocusPolicy(Qt::NoFocus); - } - void setTitle(const QString &text) { - myText = text; - update(); - } -}; -} -} - void TaskBox::actionEvent (QActionEvent* e) { QAction *action = e->action(); diff --git a/src/Gui/TaskView/TaskView.h b/src/Gui/TaskView/TaskView.h index 9b388d5a2..72b8100f7 100644 --- a/src/Gui/TaskView/TaskView.h +++ b/src/Gui/TaskView/TaskView.h @@ -57,6 +57,18 @@ public: //~TaskContent(); }; +class GuiExport TaskGroup : public iisTaskGroup, public TaskContent +{ + Q_OBJECT + +public: + TaskGroup(QWidget *parent = 0); + ~TaskGroup(); + +protected: + void actionEvent (QActionEvent*); +}; + /// Father class of content with header and Icon class GuiExport TaskBox : public iisTaskBox, public TaskContent {