OSDN Git Service

[denncoCreator] Implemented change cell and cell code type command functionality.
[dennco/denncoCreator.git] / Source / visualizer / toolwindow / dctoolwindowbase.cpp
1 //  Copyright (c) 2012 Dennco Project
2 //
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.
7 //
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.
12 //
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/>.
15
16 //
17 //  Created by tkawata on Sep-30, 2012.
18 //
19 #include "dctoolwindowbase.h"
20
21 const static QString DialogContentStyle =
22         "* {color: white} "
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;"
33         "       }"
34         "QComboBox QAbstractItemView {"
35         "       background: rgb(128,128,128);"
36         "       color: white;"
37         "       selection-background-color: rgb(128,128,255);"
38         "}";
39
40 DCToolWindowBase::DCToolWindowBase(const QString &windowTitle,DCCreator *creator)
41     : QDialog(0,Qt::CustomizeWindowHint | Qt::FramelessWindowHint), d_collapsed(false), d_creator(creator)
42 {
43     setWindowOpacity(0.8);
44     setLayout(new QVBoxLayout);
45     layout()->setContentsMargins(0,0,0,0);
46
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);
55
56     layout()->addWidget(d_titleButton);
57
58     d_layout = new QVBoxLayout;
59     d_layout->setContentsMargins(6,6,6,9);
60     ((QVBoxLayout*)layout())->addLayout(d_layout);
61
62     setStyleSheet(DialogContentStyle);
63
64 }
65
66 DCToolWindowBase::~DCToolWindowBase()
67 {
68     this->disconnect();
69 }
70
71 void DCToolWindowBase::setButtonedWindowTitle(const QString &title)
72 {
73     d_titleButton->setText(title);
74 }
75
76 void DCToolWindowBase::resizeEvent(QResizeEvent *event)
77 {
78 }
79
80 void DCToolWindowBase::slotMoveWindow(int dx, int dy)
81 {
82     QRect rect = geometry();
83     move(rect.x() + dx, rect.y() + dy);
84 }
85
86 void DCToolWindowBase::slotExpandOrCollapse()
87 {
88     d_collapsed = !d_collapsed;
89
90     if (d_collapsed)
91     {
92         d_rect = QRect(geometry());
93         resize(d_rect.width(), d_titleButtonHeight);
94     }
95     else
96     {
97         resize(d_rect.width(), d_rect.height());
98     }
99 }
100
101 void DCToolWindowBase::slotDragModeFinished()
102 {
103     emit dragMoveFinished();
104 }
105
106 DCToolWindowTitleBar::DCToolWindowTitleBar(const QString &windowTitle, QWidget *parent) : QPushButton(windowTitle, parent)
107 {
108     setStyleSheet("background-color: rgb(54,72,237); color: white;");
109 }
110
111 DCToolWindowTitleBar::~DCToolWindowTitleBar()
112 {
113     this->disconnect();
114 }
115
116 void DCToolWindowTitleBar::mousePressEvent(QMouseEvent *event)
117 {
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();
124     d_clickTime.start();
125 }
126
127 void DCToolWindowTitleBar::mouseMoveEvent(QMouseEvent *event)
128 {
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();
135     emit moved(dx,dy);
136 }
137
138 void DCToolWindowTitleBar::mouseReleaseEvent(QMouseEvent *event)
139 {
140     QPushButton::mouseReleaseEvent(event);
141     QPoint p = QCursor::pos();
142     int dx = p.x() - d_dragStartX;
143     int dy = p.y() - d_dragStartY;
144
145     bool wasDrag = !(d_clickTime.elapsed() < 500 && dx * dx + dy * dy < 400);
146
147     if (!wasDrag)
148     {
149         emit expandOrCollapse();
150     }
151     else
152     {
153         emit dragMoveFinished();
154     }
155 }
156