54 #include <QVBoxLayout>
56 #include <QToolButton>
58 #include <QMouseEvent>
63 #include "SideElement.hh"
68 QWidget *_headerAreaWidget) :
71 headerAreaWidget_(_headerAreaWidget),
80 QHBoxLayout *hl =
new QHBoxLayout;
81 hl->setContentsMargins(2, 2, 2, 2);
85 label_ =
new QLabel (_name);
86 label_->setFont (font);
88 iconHolder_ =
new QLabel ();
91 iconHolder_->setPixmap( icon_->pixmap(22,22) );
93 QPixmap pic(QSize(22,22));
94 pic.fill( QColor(0,0,0,0) );
96 iconHolder_->setPixmap( pic );
99 detachButton_ =
new QToolButton ();
100 detachButton_->setAutoRaise(
true);
101 hl->addWidget (iconHolder_);
102 hl->addWidget (label_);
103 if (headerAreaWidget_) {
104 headerAreaWidget_->setVisible(
false);
105 connect(
this, SIGNAL(toggleActive(
bool)), headerAreaWidget_, SLOT(setVisible(
bool)));
106 hl->addWidget (headerAreaWidget_);
109 hl->addWidget (detachButton_);
112 QIcon detachIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"button-detach.png");
113 detachIcon.addPixmap(QPixmap(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"button-detach_over.png"), QIcon::Active);
114 detachIcon.addPixmap(QPixmap(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"button-detach_over.png"), QIcon::Selected);
116 detachAction_ =
new QAction ( detachIcon,
"",
this);
117 detachAction_->setToolTip( tr(
"Show as separate window") );
118 detachAction_->setCheckable (
true);
119 detachButton_->setDefaultAction (detachAction_);
121 connect (detachAction_, SIGNAL (triggered (
bool)),
this, SLOT (
detachPressed (
bool)));
125 QFrame *f =
new QFrame ();
126 f->setFrameShape (QFrame::HLine);
128 mainLayout_ =
new QVBoxLayout;
130 mainLayout_->addWidget (f);
131 mainLayout_->addWidget (tra);
132 mainLayout_->addWidget (_w);
133 mainLayout_->setSpacing (0);
134 mainLayout_->setContentsMargins(0, 0, 0, 0);
135 setLayout (mainLayout_);
145 disconnect(dialog_,SIGNAL(finished(
int)),
this,SLOT(
dialogClosed()));
148 widget_->setParent (0);
149 if (headerAreaWidget_)
150 headerAreaWidget_->setParent(0);
160 dialog_->activateWindow ();
171 font.setBold (active_);
172 label_->setFont (font);
174 emit toggleActive(active_);
185 dialog_->activateWindow ();
189 const bool doEmit = (active_ != _active);
197 font.setBold (active_);
198 label_->setFont (font);
200 if (doEmit) emit toggleActive(active_);
210 mainLayout_->removeWidget (widget_);
211 dialog_ =
new QDialog(0, Qt::Window);
212 dialog_->setWindowTitle (name_);
213 dialog_->setWindowIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"button-detach.png"));
214 dialog_->setLayout (
new QVBoxLayout);
215 dialog_->resize (widget_->size ());
218 int x = (window ()->width () - widget_->width ()) / 2;
219 x += window ()->x ();
221 int y = (window ()->height () - widget_->height ()) / 2;
222 y += window ()->y ();
224 dialog_->move (x, y);
226 dialog_->layout ()->addWidget (widget_);
228 widget_->setAttribute(Qt::WA_DeleteOnClose,
false);
231 connect (dialog_, SIGNAL(finished (
int)),
this, SLOT(
dialogClosed ()));
235 font.setItalic (
true);
236 label_->setFont (font);
248 mainLayout_->addWidget (widget_);
249 widget_->setAttribute(Qt::WA_DeleteOnClose,
true);
256 detachAction_->setChecked (
false);
258 font.setBold (active_);
259 label_->setFont (font);
266 _settings.beginGroup (name_);
267 _settings.setValue (
"Active",
active());
268 _settings.setValue (
"Detached", (dialog_ != 0));
269 _settings.setValue (
"DialogGeometry", (dialog_) ? dialog_->saveGeometry (): QByteArray());
270 _settings.endGroup ();
276 _settings.beginGroup (name_);
278 bool active = _settings.value (
"Active", active_).toBool ();
279 const bool doEmit = (active_ !=
active);
288 font.setBold (active_);
289 label_->setFont (font);
291 if (doEmit) emit toggleActive(active_);
293 if (_settings.value (
"Detached",
false).toBool () && !dialog_)
297 dialog_->restoreGeometry (_settings.value (
"DialogGeometry").toByteArray ());
299 _settings.endGroup ();
311 return widget_->isVisible();
329 void SideElement::TopArea::mousePressEvent (QMouseEvent *_event)
void labelPress()
Called on mouse press.
void restoreState(QSettings &_settings)
restores the state
const QString & name()
return the name
void setActive(bool _active)
Set the element as active.
QWidget const * widget()
returns the pointer to the plugin tool widget
void saveState(QSettings &_settings)
saves the current state
bool active()
returns if the SideElement is active
void dialogClosed()
Called if a detached dialog was closed.
~SideElement()
Destructor.
Clickable area inside of the side element.
SideElement(SideArea *_parent, QWidget *_w, QString _name, QIcon *_icon, QWidget *_headerAreaWidget)
void detachPressed(bool _checked)
Called if the detach button was pressed.