Skip to content

Commit 02ce72a

Browse files
committed
Loads of small changes
* Nitpicky style changes * Improvements to scroll wheel zooming * libusb init error dialog * Moved all cutting parameters into single struct. * Get version code from qmake project file. * Disable Reload when no file is open. * Use C++11. * Ignore .user files in git.
1 parent ef5a22a commit 02ce72a

19 files changed

Lines changed: 145 additions & 133 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ ui_CutDialog.h
2626
ui_CuttingDialog.h
2727
ui_MainWindow.h
2828
.gitignore
29+
*.user

Common.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,31 +52,31 @@ class Error
5252
const Error Success(true);
5353
const Error Failure(false);
5454

55-
/** Integer to string. */
55+
// Integer to string.
5656
inline string ItoS(int I)
5757
{
5858
std::stringstream S;
5959
S << I;
6060
return S.str();
6161
}
6262

63-
/** Unsigned integer to string. */
63+
// Unsigned integer to string.
6464
inline string UItoS(unsigned int I)
6565
{
6666
std::stringstream S;
6767
S << I;
6868
return S.str();
6969
}
7070

71-
/** Unsigned long long to string. */
71+
// Unsigned long long to string.
7272
inline string ULLtoS(unsigned long long I)
7373
{
7474
char out[128];
7575
sprintf(out, "%lld", I);
7676
return out;
7777
}
7878

79-
/** String to integer, returns Fail on fail. */
79+
// String to integer, returns Fail on fail.
8080
inline int StoI(const string& S, int Fail = 0)
8181
{
8282
char* EP;
@@ -87,7 +87,7 @@ inline int StoI(const string& S, int Fail = 0)
8787
return R;
8888
}
8989

90-
/** String to unsigned integer, returns Fail on fail. */
90+
// String to unsigned integer, returns Fail on fail.
9191
inline unsigned int StoUI(const string& S, unsigned int Fail = 0)
9292
{
9393
char* EP;
@@ -98,7 +98,7 @@ inline unsigned int StoUI(const string& S, unsigned int Fail = 0)
9898
return R;
9999
}
100100

101-
/** String to unsigned integer, returns Fail on fail. */
101+
// String to unsigned integer, returns Fail on fail.
102102
inline unsigned int StoULL(const string& S, unsigned long long Fail = 0)
103103
{
104104
char* EP;
@@ -109,7 +109,7 @@ inline unsigned int StoULL(const string& S, unsigned long long Fail = 0)
109109
return R;
110110
}
111111

112-
/** Get an environmental variable. */
112+
// Get an environmental variable.
113113
inline string GetEnv(const string& Var)
114114
{
115115
char* V = getenv(Var.c_str());

CutDialog.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
2020
***************************************************************************/
2121

22-
#ifndef CUTDIALOG_H
23-
#define CUTDIALOG_H
22+
#pragma once
2423

2524
#include <QDialog>
2625

@@ -43,10 +42,12 @@ class CutDialog : public QDialog
4342
int speed() const;
4443
// The cutting pressure (1-33).
4544
int pressure() const;
46-
// Track enhancing.
45+
// Track enhancing. This is when the cutter rolls the media backwards and forwards
46+
// a few times before cutting in order to indent it with tracks where the rollors are.
47+
// The idea is that it will slip less after that is done.
4748
bool trackEnhancing() const;
4849

49-
// Whether to search
50+
// Whether to search.
5051
bool regMark() const;
5152
bool regSearch() const;
5253
// Positions of the registration marks.
@@ -57,10 +58,8 @@ class CutDialog : public QDialog
5758
void changeEvent(QEvent *e);
5859

5960
private slots:
60-
// When they change the media, update the default speed and pressure.
61+
// When they change the media selection, update the default speed and pressure.
6162
void onMediaChanged(int idx);
6263
private:
6364
Ui::CutDialog *ui;
6465
};
65-
66-
#endif // CUTDIALOG_H

CuttingDialog.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ void CuttingDialog::changeEvent(QEvent *e)
5959
}
6060

6161

62-
void CuttingDialog::startCut(QList<QPolygonF> cuts, double mediawidth, double mediaheight, int media, int speed,
63-
int pressure, bool trackenhancing,
64-
bool regmark, bool regsearch, double regwidth, double reglength)
62+
void CuttingDialog::startCut(const CutParams& params)
6563
{
6664
if (thread)
6765
{
@@ -73,8 +71,7 @@ void CuttingDialog::startCut(QList<QPolygonF> cuts, double mediawidth, double me
7371
connect(thread, SIGNAL(success()), SLOT(onSuccess()));
7472
connect(thread, SIGNAL(error(QString)), SLOT(onError(QString)));
7573

76-
thread->setParams(cuts, mediawidth, mediaheight, media, speed, pressure, trackenhancing,
77-
regmark, regsearch, regwidth, reglength);
74+
thread->setParams(params);
7875

7976
thread->start();
8077
}

CuttingDialog.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ class CuttingDialog : public QDialog
4141

4242
// Start the cutting thread. Call this only once, before the dialog is shown.
4343
// It creates the thread, passes it the cutting details, and runs it.
44-
void startCut(QList<QPolygonF> cuts, double mediawidth, double mediaheigt, int media, int speed,
45-
int pressure, bool trackenhancing, bool regmark, bool regsearch,
46-
double regwidth, double reglength);
44+
void startCut(const CutParams& params);
4745

4846
protected:
4947
void changeEvent(QEvent *e);

CuttingThread.cpp

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,40 +26,19 @@
2626
CuttingThread::CuttingThread(QObject *parent) :
2727
QThread(parent)
2828
{
29-
_media = 300;
30-
_speed = 10;
31-
_pressure = 10;
32-
_trackenhancing = false;
33-
_regmark = false;
34-
_regsearch = false;
35-
_regwidth = 0.0;
36-
_reglength = 0.0;
29+
3730
}
3831

3932

40-
void CuttingThread::setParams(QList<QPolygonF> cuts, double mediawidth, double mediaheight, int media,
41-
int speed, int pressure, bool trackenhancing,
42-
bool regmark, bool regsearch, float regwidth, float reglength)
33+
void CuttingThread::setParams(const CutParams& p)
4334
{
44-
// TODO: Move all this into a structure.
45-
_cuts = cuts;
46-
_media = media;
47-
_speed = speed;
48-
_pressure = pressure;
49-
_trackenhancing = trackenhancing;
50-
_regmark = regmark;
51-
_regsearch = regsearch;
52-
_regwidth = regwidth;
53-
_reglength = reglength;
54-
_mediawidth = mediawidth;
55-
_mediaheight = mediaheight;
35+
params = p;
5636
}
5737

5838

5939
void CuttingThread::run()
6040
{
61-
Error e = Cut(_cuts, _mediawidth, _mediaheight, _media, _speed, _pressure, _trackenhancing,
62-
_regmark, _regsearch, _regwidth, _reglength);
41+
Error e = Cut(params);
6342
if (e)
6443
emit success();
6544
else

CuttingThread.h

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,29 @@
3434
// 4. Call start().
3535
// 5. Wait for success() or error().
3636

37+
struct CutParams
38+
{
39+
QList<QPolygonF> cuts;
40+
double mediawidth = 0.0;
41+
double mediaheight = 0.0;
42+
int media = 300;
43+
int speed = 10;
44+
int pressure = 10;
45+
bool trackenhancing = false;
46+
bool regmark = false;
47+
bool regsearch = false;
48+
double regwidth = 0.0;
49+
double regheight = 0.0;
50+
};
51+
3752
class CuttingThread : public QThread
3853
{
3954
Q_OBJECT
4055
public:
4156
explicit CuttingThread(QObject *parent = 0);
4257

4358
// Set the parameters to use for the cut.
44-
void setParams(QList<QPolygonF> cuts, double mediawidth, double mediaheight, int media, int speed, int pressure,
45-
bool trackenhancing, bool regmark, bool regsearch, float regwidth, float reglength);
59+
void setParams(const CutParams& params);
4660

4761
signals:
4862
// Emitted if the cutting was (as far as we can tell) successful.
@@ -57,15 +71,6 @@ public slots:
5771
void run();
5872

5973
private:
60-
QList<QPolygonF> _cuts;
61-
double _mediawidth;
62-
double _mediaheight;
63-
int _media;
64-
int _speed;
65-
int _pressure;
66-
bool _trackenhancing;
67-
bool _regmark;
68-
bool _regsearch;
69-
double _regwidth;
70-
double _reglength;
74+
CutParams params;
75+
7176
};

MainWindow.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,21 @@ void MainWindow::on_actionCut_triggered()
258258
// Create a new dialog and run the actual cutting in a different thread.
259259

260260
CuttingDialog* cuttingDlg = new CuttingDialog(this);
261-
cuttingDlg->startCut(paths, mediaSize.width(), mediaSize.height(), cutDialog->media(), cutDialog->speed(),
262-
cutDialog->pressure(), cutDialog->trackEnhancing(),
263-
cutDialog->regMark(), cutDialog->regSearch(),
264-
cutDialog->regWidth(), cutDialog->regHeight());
261+
262+
CutParams params;
263+
params.cuts = paths;
264+
params.mediawidth = mediaSize.width();
265+
params.mediaheight = mediaSize.height();
266+
params.media = cutDialog->media();
267+
params.pressure = cutDialog->pressure();
268+
params.regwidth = cutDialog->regWidth();
269+
params.regheight = cutDialog->regHeight();
270+
params.regmark = cutDialog->regMark();
271+
params.regsearch = cutDialog->regSearch();
272+
params.speed = cutDialog->speed();
273+
params.trackenhancing = cutDialog->trackEnhancing();
274+
275+
cuttingDlg->startCut(params);
265276
cuttingDlg->show();
266277
}
267278

@@ -382,6 +393,7 @@ void MainWindow::setFileLoaded(QString filename)
382393
ui->actionZoom_In->setEnabled(e);
383394
ui->actionZoom_Out->setEnabled(e);
384395
ui->actionCut->setEnabled(e);
396+
ui->actionReload->setEnabled(e);
385397

386398
}
387399

@@ -391,9 +403,18 @@ bool MainWindow::eventFilter(QObject *o, QEvent *e)
391403
{
392404
if (e->type() == QEvent::Wheel)
393405
{
406+
// Anchor under the mouse pointer when using the mouse wheel.
407+
// This doesn't quite work as nicely as I'd like because it clamps the scrolling
408+
// precisely to the scene boundary. It's a bit hard to zoom to corners. Oh well.
409+
ui->graphicsView->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
394410
QWheelEvent *w = dynamic_cast<QWheelEvent*>(e);
395-
if(w->delta() <= 0) on_actionZoom_In_triggered();
396-
else on_actionZoom_Out_triggered();
411+
if (w->delta() <= 0)
412+
on_actionZoom_Out_triggered();
413+
else
414+
on_actionZoom_In_triggered();
415+
416+
// Anchor in view centre for keyboard shortcuts.
417+
ui->graphicsView->setTransformationAnchor(QGraphicsView::AnchorViewCenter);
397418
return true;
398419
}
399420
}

MainWindow.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
2020
***************************************************************************/
2121

22-
#ifndef MAINWINDOW_H
23-
#define MAINWINDOW_H
22+
#pragma once
2423

2524
#include <QMainWindow>
2625

@@ -99,5 +98,3 @@ private slots:
9998
bool eventFilter(QObject *o, QEvent *e);
10099
void loadFile();
101100
};
102-
103-
#endif // MAINWINDOW_H

MainWindow.ui

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@
164164
</property>
165165
</action>
166166
<action name="actionReload">
167+
<property name="enabled">
168+
<bool>false</bool>
169+
</property>
167170
<property name="text">
168171
<string>Reload</string>
169172
</property>

0 commit comments

Comments
 (0)