1 /*******************************************************************
2
3 Part of the Fritzing project - http://fritzing.org
4 Copyright (c) 2007-2014 Fachhochschule Potsdam - http://fh-potsdam.de
5
6 Fritzing is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Fritzing is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Fritzing. If not, see <http://www.gnu.org/licenses/>.
18
19 ********************************************************************
20
21 $Revision: 6904 $:
22 $Author: irascibl@gmail.com $:
23 $Date: 2013-02-26 16:26:03 +0100 (Di, 26. Feb 2013) $
24
25 ********************************************************************/
26
27 #include "autorouteprogressdialog.h"
28 #include "../debugdialog.h"
29 #include "zoomcontrols.h"
30
31 #include <QLabel>
32 #include <QComboBox>
33 #include <QPushButton>
34 #include <QLocale>
35 #include <QGroupBox>
36 #include <QScrollBar>
37
38 static const int ScrollAmount = 40;
39
ArrowButton(int scrollX,int scrollY,ZoomableGraphicsView * view,const QString & path)40 ArrowButton::ArrowButton(int scrollX, int scrollY, ZoomableGraphicsView * view, const QString & path) : QLabel() {
41 m_scrollX = scrollX;
42 m_scrollY = scrollY;
43 m_view = view;
44 setPixmap(QPixmap(path));
45 }
46
mousePressEvent(QMouseEvent * event)47 void ArrowButton::mousePressEvent(QMouseEvent *event) {
48 Q_UNUSED(event);
49 if (m_scrollX != 0) {
50 QScrollBar * scrollBar = m_view->horizontalScrollBar();
51 scrollBar->setValue(scrollBar->value() - m_scrollX);
52 }
53 else if (m_scrollY != 0) {
54 QScrollBar * scrollBar = m_view->verticalScrollBar();
55 scrollBar->setValue(scrollBar->value() - m_scrollY);
56 }
57 }
58
59 /////////////////////////////////////
60
AutorouteProgressDialog(const QString & title,bool zoomAndPan,bool stopButton,bool bestButton,bool spin,ZoomableGraphicsView * view,QWidget * parent)61 AutorouteProgressDialog::AutorouteProgressDialog(const QString & title, bool zoomAndPan, bool stopButton, bool bestButton, bool spin, ZoomableGraphicsView * view, QWidget *parent) : QDialog(parent)
62 {
63 Qt::WindowFlags flags = windowFlags();
64 flags ^= Qt::WindowCloseButtonHint;
65 flags ^= Qt::WindowContextHelpButtonHint;
66 setWindowFlags(flags);
67
68 this->setWindowTitle(title);
69
70 QVBoxLayout * vLayout = new QVBoxLayout(this);
71
72 m_progressBar = new QProgressBar(this);
73 vLayout->addWidget(m_progressBar);
74
75 m_spinLabel = NULL;
76 m_spinBox = NULL;
77
78 if (spin) {
79 QFrame * frame = new QFrame(this);
80 m_spinLabel = new QLabel(this);
81 m_spinBox = new QSpinBox(this);
82 m_spinBox->setMinimum(1);
83 m_spinBox->setMaximum(99999);
84 connect(m_spinBox, SIGNAL(valueChanged(int)), this, SLOT(internalSpinChange(int)));
85 QHBoxLayout * hBoxLayout = new QHBoxLayout(frame);
86 hBoxLayout->addStretch();
87 hBoxLayout->addWidget(m_spinLabel);
88 hBoxLayout->addWidget(m_spinBox);
89 vLayout->addWidget(frame);
90 }
91
92 m_message = new QLabel(this);
93 vLayout->addWidget(m_message);
94 m_message2 = new QLabel(this);
95 vLayout->addWidget(m_message2);
96
97 if (zoomAndPan) {
98 QGroupBox * groupBox = new QGroupBox(tr("zoom and pan controls"));
99 QHBoxLayout *lo2 = new QHBoxLayout(groupBox);
100 lo2->setSpacing(1);
101 lo2->setMargin(0);
102
103 //TODO: use the zoom slider instead
104 lo2->addWidget(new ZoomControls(view, groupBox));
105
106 lo2->addSpacerItem(new QSpacerItem ( 10, 0, QSizePolicy::Expanding));
107
108 QFrame * frame = new QFrame();
109 QGridLayout *gridLayout = new QGridLayout(frame);
110
111 QString imgPath = ":/resources/images/icons/arrowButton%1.png";
112 ArrowButton * label = new ArrowButton(0, -ScrollAmount, view, imgPath.arg("Up"));
113 gridLayout->addWidget(label, 0, 1);
114
115 label = new ArrowButton(0, ScrollAmount, view, imgPath.arg("Down"));
116 gridLayout->addWidget(label, 2, 1);
117
118 label = new ArrowButton(-ScrollAmount, 0, view, imgPath.arg("Left"));
119 gridLayout->addWidget(label, 0, 0, 3, 1);
120
121 label = new ArrowButton(ScrollAmount, 0, view, imgPath.arg("Right"));
122 gridLayout->addWidget(label, 0, 2, 3, 1);
123
124
125 lo2->addWidget(frame);
126
127 vLayout->addSpacing(7);
128 vLayout->addWidget(groupBox);
129 vLayout->addSpacing(7);
130 }
131
132 //QPushButton * button = new QPushButton(tr("Skip current trace"), this);
133 //connect(button, SIGNAL(clicked()), this, SLOT(sendSkip()));
134 //vLayout->addWidget(button);
135
136 m_buttonBox = new QDialogButtonBox(stopButton ? QDialogButtonBox::Ok | QDialogButtonBox::Cancel : QDialogButtonBox::Cancel);
137 if (stopButton) {
138 m_buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Stop Now"));
139 connect(m_buttonBox, SIGNAL(accepted()), this, SLOT(sendStop()));
140 }
141 if (bestButton) {
142 QPushButton * best = new QPushButton(tr("Best So Far"));
143 m_buttonBox->addButton(best, QDialogButtonBox::ActionRole);
144 connect(best, SIGNAL(clicked()), this, SLOT(sendBest()));
145 }
146
147
148 m_buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Cancel"));
149 connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(sendCancel()));
150
151 vLayout->addWidget(m_buttonBox);
152
153 this->setLayout(vLayout);
154 }
155
~AutorouteProgressDialog()156 AutorouteProgressDialog::~AutorouteProgressDialog() {
157 }
158
setMinimum(int minimum)159 void AutorouteProgressDialog::setMinimum(int minimum) {
160 m_progressBar->setMinimum(minimum);
161 }
162
setMaximum(int maximum)163 void AutorouteProgressDialog::setMaximum(int maximum) {
164 m_progressBar->setMaximum(maximum);
165 }
166
setValue(int value)167 void AutorouteProgressDialog::setValue(int value) {
168 m_progressBar->setValue(value);
169 }
170
sendSkip()171 void AutorouteProgressDialog::sendSkip() {
172 emit skip();
173 }
174
sendCancel()175 void AutorouteProgressDialog::sendCancel() {
176 emit cancel();
177 }
178
sendStop()179 void AutorouteProgressDialog::sendStop() {
180 emit stop();
181 }
182
sendBest()183 void AutorouteProgressDialog::sendBest() {
184 emit best();
185 }
186
closeEvent(QCloseEvent * event)187 void AutorouteProgressDialog::closeEvent(QCloseEvent *event)
188 {
189 sendCancel();
190 QDialog::closeEvent(event);
191 }
192
setMessage(const QString & text)193 void AutorouteProgressDialog::setMessage(const QString & text)
194 {
195 m_message->setText(text);
196 }
197
setMessage2(const QString & text)198 void AutorouteProgressDialog::setMessage2(const QString & text)
199 {
200 m_message2->setText(text);
201 }
202
setSpinLabel(const QString & text)203 void AutorouteProgressDialog::setSpinLabel(const QString & text)
204 {
205 m_spinLabel->setText(text);
206 }
207
setSpinValue(int value)208 void AutorouteProgressDialog::setSpinValue(int value)
209 {
210 m_spinBox->setValue(value);
211 }
212
internalSpinChange(int value)213 void AutorouteProgressDialog::internalSpinChange(int value) {
214 emit spinChange(value);
215 }
216
disableButtons()217 void AutorouteProgressDialog::disableButtons() {
218 m_buttonBox->setEnabled(false);
219 }
220