1 // Copyright (c) 2012 Dennco Project
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // Created by tkawata on Sep-30, 2012.
19 #include "dctoolwindowbase.h"
21 const static QString DialogContentStyle =
23 "QDialog {background-color: rgba(255,255,255,60);} "
24 "QRadioButton {background-color: transparent;} "
25 "QPlainTextEdit {background: black;} "
26 "QGroupBox { border: 1px solid gray; border-radius: 3px;} "
27 "QTableView { background: black;} "
28 "QPushButton { background-color: rgb(128,128,128);} "
29 "QComboBox { background-color: rgb(128,128,128); "
30 " border: 1px solid gray;"
31 " border-radius: 3px;"
32 " padding: 1px 18px 1px 3px;"
34 "QComboBox QAbstractItemView {"
35 " background: rgb(128,128,128);"
37 " selection-background-color: rgb(128,128,255);"
40 DCToolWindowBase::DCToolWindowBase(const QString &windowTitle,DCCreator *creator)
41 : QDialog(0,Qt::CustomizeWindowHint | Qt::FramelessWindowHint), d_collapsed(false), d_creator(creator)
43 setWindowOpacity(0.8);
44 setLayout(new QVBoxLayout);
45 layout()->setContentsMargins(0,0,0,0);
47 d_titleButton = new DCToolWindowTitleBar(windowTitle, this);
48 d_titleButton->setStyleSheet("* {background-color: rgb(85, 85, 255);} ");
49 connect(d_titleButton, SIGNAL(moved(int,int)), this, SLOT(slotMoveWindow(int,int)));
50 connect(d_titleButton, SIGNAL(expandOrCollapse()), this, SLOT(slotExpandOrCollapse()));
51 connect(d_titleButton, SIGNAL(dragMoveFinished()), this, SLOT(slotDragModeFinished()));
52 d_titleButtonHeight = d_titleButton->geometry().height();
53 setMinimumHeight(d_titleButtonHeight);
54 d_titleButton->setMinimumHeight(d_titleButtonHeight);
56 layout()->addWidget(d_titleButton);
58 d_layout = new QVBoxLayout;
59 d_layout->setContentsMargins(6,6,6,9);
60 ((QVBoxLayout*)layout())->addLayout(d_layout);
62 setStyleSheet(DialogContentStyle);
66 DCToolWindowBase::~DCToolWindowBase()
71 void DCToolWindowBase::setButtonedWindowTitle(const QString &title)
73 d_titleButton->setText(title);
76 void DCToolWindowBase::resizeEvent(QResizeEvent *event)
80 void DCToolWindowBase::slotMoveWindow(int dx, int dy)
82 QRect rect = geometry();
83 move(rect.x() + dx, rect.y() + dy);
86 void DCToolWindowBase::slotExpandOrCollapse()
88 d_collapsed = !d_collapsed;
92 d_rect = QRect(geometry());
93 resize(d_rect.width(), d_titleButtonHeight);
97 resize(d_rect.width(), d_rect.height());
101 void DCToolWindowBase::slotDragModeFinished()
103 emit dragMoveFinished();
106 DCToolWindowTitleBar::DCToolWindowTitleBar(const QString &windowTitle, QWidget *parent) : QPushButton(windowTitle, parent)
108 setStyleSheet("background-color: rgb(54,72,237); color: white;");
111 DCToolWindowTitleBar::~DCToolWindowTitleBar()
116 void DCToolWindowTitleBar::mousePressEvent(QMouseEvent *event)
118 QPushButton::mousePressEvent(event);
119 QPoint p = QCursor::pos();
120 d_mousePrevX = p.x();
121 d_mousePrevY = p.y();
122 d_dragStartX = p.x();
123 d_dragStartY = p.y();
127 void DCToolWindowTitleBar::mouseMoveEvent(QMouseEvent *event)
129 QPushButton::mouseMoveEvent(event);
130 QPoint p = QCursor::pos();
131 int dx = p.x() - d_mousePrevX;
132 int dy = p.y() - d_mousePrevY;
133 d_mousePrevX = p.x();
134 d_mousePrevY = p.y();
138 void DCToolWindowTitleBar::mouseReleaseEvent(QMouseEvent *event)
140 QPushButton::mouseReleaseEvent(event);
141 QPoint p = QCursor::pos();
142 int dx = p.x() - d_dragStartX;
143 int dy = p.y() - d_dragStartY;
145 bool wasDrag = !(d_clickTime.elapsed() < 500 && dx * dx + dy * dy < 400);
149 emit expandOrCollapse();
153 emit dragMoveFinished();