48 #include <QVBoxLayout> 50 #include <QToolButton> 52 #include <QMouseEvent> 57 #include "SideElement.hh" 62 QWidget *_headerAreaWidget) :
65 headerAreaWidget_(_headerAreaWidget),
74 QHBoxLayout *hl =
new QHBoxLayout;
75 hl->setContentsMargins(2, 2, 2, 2);
79 label_ =
new QLabel (_name);
80 label_->setFont (font);
82 iconHolder_ =
new QLabel ();
85 iconHolder_->setPixmap( icon_->pixmap(22,22) );
87 QPixmap pic(QSize(22,22));
88 pic.fill( QColor(0,0,0,0) );
90 iconHolder_->setPixmap( pic );
93 detachButton_ =
new QToolButton ();
94 detachButton_->setAutoRaise(
true);
95 hl->addWidget (iconHolder_);
96 hl->addWidget (label_);
97 if (headerAreaWidget_) {
98 headerAreaWidget_->setVisible(
false);
99 connect(
this, SIGNAL(toggleActive(
bool)), headerAreaWidget_, SLOT(setVisible(
bool)));
100 hl->addWidget (headerAreaWidget_);
103 hl->addWidget (detachButton_);
106 QIcon detachIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"button-detach.png");
107 detachIcon.addPixmap(QPixmap(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"button-detach_over.png"), QIcon::Active);
108 detachIcon.addPixmap(QPixmap(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"button-detach_over.png"), QIcon::Selected);
110 detachAction_ =
new QAction ( detachIcon,
"",
this);
111 detachAction_->setToolTip( tr(
"Show as separate window") );
112 detachAction_->setCheckable (
true);
113 detachButton_->setDefaultAction (detachAction_);
115 connect (detachAction_, SIGNAL (triggered (
bool)),
this, SLOT (
detachPressed (
bool)));
119 QFrame *f =
new QFrame ();
120 f->setFrameShape (QFrame::HLine);
122 mainLayout_ =
new QVBoxLayout;
124 mainLayout_->addWidget (f);
125 mainLayout_->addWidget (tra);
126 mainLayout_->addWidget (_w);
127 mainLayout_->setSpacing (0);
128 mainLayout_->setContentsMargins(0, 0, 0, 0);
129 setLayout (mainLayout_);
139 disconnect(dialog_,SIGNAL(finished(
int)),
this,SLOT(
dialogClosed()));
142 widget_->setParent (0);
143 if (headerAreaWidget_)
144 headerAreaWidget_->setParent(0);
154 dialog_->activateWindow ();
165 font.setBold (active_);
166 label_->setFont (font);
168 emit toggleActive(active_);
179 dialog_->activateWindow ();
183 const bool doEmit = (active_ != _active);
191 font.setBold (active_);
192 label_->setFont (font);
194 if (doEmit) emit toggleActive(active_);
204 mainLayout_->removeWidget (widget_);
205 dialog_ =
new QDialog(0, Qt::Window);
206 dialog_->setWindowTitle (name_);
207 dialog_->setWindowIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"button-detach.png"));
208 dialog_->setLayout (
new QVBoxLayout);
209 dialog_->resize (widget_->size ());
212 int x = (window ()->width () - widget_->width ()) / 2;
213 x += window ()->x ();
215 int y = (window ()->height () - widget_->height ()) / 2;
216 y += window ()->y ();
218 dialog_->move (x, y);
220 dialog_->layout ()->addWidget (widget_);
222 widget_->setAttribute(Qt::WA_DeleteOnClose,
false);
225 connect (dialog_, SIGNAL(finished (
int)),
this, SLOT(
dialogClosed ()));
229 font.setItalic (
true);
230 label_->setFont (font);
242 mainLayout_->addWidget (widget_);
243 widget_->setAttribute(Qt::WA_DeleteOnClose,
true);
250 detachAction_->setChecked (
false);
252 font.setBold (active_);
253 label_->setFont (font);
260 _settings.beginGroup (name_);
261 _settings.setValue (
"Active",
active());
262 _settings.setValue (
"Detached", (dialog_ != 0));
263 _settings.setValue (
"DialogGeometry", (dialog_) ? dialog_->saveGeometry (): QByteArray());
264 _settings.endGroup ();
270 _settings.beginGroup (name_);
272 bool active = _settings.value (
"Active", active_).toBool ();
273 const bool doEmit = (active_ !=
active);
282 font.setBold (active_);
283 label_->setFont (font);
285 if (doEmit) emit toggleActive(active_);
287 if (_settings.value (
"Detached",
false).toBool () && !dialog_)
291 dialog_->restoreGeometry (_settings.value (
"DialogGeometry").toByteArray ());
293 _settings.endGroup ();
305 return widget_->isVisible();
323 void SideElement::TopArea::mousePressEvent (QMouseEvent *_event)
bool active()
returns if the SideElement is active
SideElement(SideArea *_parent, QWidget *_w, QString _name, QIcon *_icon, QWidget *_headerAreaWidget)
void detachPressed(bool _checked)
Called if the detach button was pressed.
void saveState(QSettings &_settings)
saves the current state
void restoreState(QSettings &_settings)
restores the state
const QString & name()
return the name
QWidget const * widget()
returns the pointer to the plugin tool widget
void setActive(bool _active)
Set the element as active.
void dialogClosed()
Called if a detached dialog was closed.
~SideElement()
Destructor.
void labelPress()
Called on mouse press.
Clickable area inside of the side element.