Developer documentation | Axl-2.5.1

axlInspectorStack.cpp
Go to the documentation of this file.
1 /* axlInspectorStack.cpp ---
2  *
3  * Author: Meriadeg Perrinel
4  * Copyright (C) 2008 - Julien Wintz, Inria.
5  * Created: Tue Mar 15 14:09:00 2011 (+0100)
6  * Version: $Id$
7  * Last-Updated: Tue Dec 27 12:56:36 2011 (+0100)
8  * By: Julien Wintz
9  * Update #: 89
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
20 #include "axlInspectorStack.h"
21 
22 #include <dtkCoreSupport/dtkGlobal.h>
23 
24 #include <dtkGuiSupport/dtkSpacer.h>
25 
26 #include <QtGui>
27 
28 class axlInspectorStackPrivate
29 {
30 public:
31  QStackedWidget *widget;
32  QToolBar *bar;
33 
34  QMap<QAction *, QWidget *> actions;
35 };
36 
37 axlInspectorStack::axlInspectorStack(QWidget *parent) : QFrame(parent), d(new axlInspectorStackPrivate)
38 {
39  d->widget = new QStackedWidget(this);
40  d->widget->setFixedWidth(290);
41  // d->widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
42 
43  d->bar = new QToolBar(this);
44  d->bar->setFloatable(false);
45 
46  QScrollArea *area = new QScrollArea(this);
47  area->setAttribute(Qt::WA_MacShowFocusRect, false);
48  area->setFrameShape(QFrame::NoFrame);
49  area->setContentsMargins(0, 0, 0, 0);
50  area->setWidget(d->widget);
51  area->setWidgetResizable(true);
52 
53  QVBoxLayout *layout = new QVBoxLayout(this);
54  layout->setContentsMargins(0, 0, 0, 0);
55  layout->addWidget(d->bar);
56  layout->addWidget(area);
57  layout->setSpacing(0);
58 
59 
60 
61  this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
62 }
63 
65 {
66  delete d;
67 
68  d = NULL;
69 }
70 
71 void axlInspectorStack::addWidget(QString title, QWidget *widget)
72 {
73  static int count = 0;
74 
75  d->widget->addWidget(widget);
76 
77  QAction *action = d->bar->addAction(title, this, SLOT(onActionClicked()));
78  action->setShortcut(QKeySequence(QString("Ctrl+%1").arg(QString::number(++count))));
79 
80  this->addAction(action);
81 
82  d->actions.insert(action, widget);
83 }
84 
85 int axlInspectorStack::width(void) const
86 {
87  return QFrame::width();
88 }
89 
91 {
92  this->setFixedWidth(width);
93 }
94 
96 {
97  d->widget->setCurrentWidget(d->actions.value(dynamic_cast<QAction *>(this->sender())));
98 }
void addWidget(QString title, QWidget *widget)
void setWidth(int width)
int width(void) const
axlInspectorStack(QWidget *parent=0)