Skip to content

Commit db1b6fd

Browse files
Adapted to openCV 4.1 + holes count + Quit button
1 parent 308f87d commit db1b6fd

File tree

4 files changed

+85
-1
lines changed

4 files changed

+85
-1
lines changed

mainwindow.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ MainWindow::MainWindow(QWidget *parent) :
2727
{
2828
ui->setupUi(this);
2929

30+
// window
31+
setWindowFlags((((windowFlags() | Qt::CustomizeWindowHint)
32+
& ~Qt::WindowCloseButtonHint) | Qt::WindowMinMaxButtonsHint)); // don't show buttons in title bar
33+
this->setWindowState(Qt::WindowMaximized); // maximize window
3034
setFocusPolicy(Qt::StrongFocus); // catch keyboard and mouse in priority
3135

3236
// Populate combo lists
@@ -69,6 +73,15 @@ MainWindow::~MainWindow()
6973

7074
/////////////////// GUI //////////////////////
7175

76+
void MainWindow::on_button_quit_clicked()
77+
{
78+
int quit = QMessageBox::question(this, "Quit this wonderful program", "Are you sure you want to quit?", QMessageBox::Yes|QMessageBox::No); // quit, are you sure ?
79+
if (quit == QMessageBox::No) // don't quit !
80+
return;
81+
82+
QCoreApplication::quit();
83+
}
84+
7285
void MainWindow::on_Tabs_currentChanged(int) // when a tab is clicked
7386
{
7487
if(ui->Tabs->currentIndex()==2) ui->label_segmentation->setCursor(Qt::PointingHandCursor); // labels tab ? => labels view cursor
@@ -522,6 +535,8 @@ void MainWindow::on_button_save_session_clicked() // save session files
522535
std::string filesession = filename.toUtf8().constData(); // base file name
523536
size_t pos = filesession.find("-segmentation-data.xml");
524537
if (pos != std::string::npos) filesession.erase(pos, filesession.length());
538+
pos = filesession.find(".xml");
539+
if (pos != std::string::npos) filesession.erase(pos, filesession.length());
525540

526541
bool write;
527542
write = cv::imwrite(filesession + "-segmentation-mask.png", mask); // save mask
@@ -581,6 +596,16 @@ void MainWindow::on_button_save_session_clicked() // save session files
581596
fs.release(); // close file
582597

583598
QMessageBox::information(this, "Save segmentation session", "Session saved with base name:\n" + QString::fromStdString(filesession));
599+
600+
basefile = filesession; // base file name and dir are used after to save other files
601+
basedir = basefile;
602+
size_t found = basefile.find_last_of("/"); // find last directory
603+
basedir = basedir.substr(0,found) + "/"; // extract file location
604+
basefile = basefile.substr(found+1); // delete ending slash
605+
pos = basefile.find("-segmentation-data");
606+
if (pos != std::string::npos) basefile.erase(pos, basefile.length());
607+
ui->label_filename->setText(filename); // display file name in ui
608+
SaveDirBaseFile(); // Save current path to ini file
584609
}
585610

586611
void MainWindow::on_button_load_session_clicked() // load previous session
@@ -599,11 +624,13 @@ void MainWindow::on_button_load_session_clicked() // load previous session
599624
size_t found = basefile.find_last_of("/"); // find last directory
600625
basedir = basedir.substr(0,found) + "/"; // extract file location
601626
basefile = basefile.substr(found+1); // delete ending slash
627+
size_t pos = basefile.find("-segmentation-data");
628+
if (pos != std::string::npos) basefile.erase(pos, basefile.length());
602629
ui->label_filename->setText(filename); // display file name in ui
603630
SaveDirBaseFile(); // Save current path to ini file
604631

605632
std::string filesession = filename.toUtf8().constData(); // base file name
606-
size_t pos = filesession.find("-segmentation-data.xml");
633+
pos = filesession.find("-segmentation-data.xml");
607634
if (pos != std::string::npos) filesession.erase(pos, filesession.length());
608635

609636
InitializeValues(); // reinit all variables

mainwindow.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ private slots:
5050
//// UI
5151
void InitializeValues(); // well named !
5252

53+
//// quit
54+
void on_button_quit_clicked();
55+
5356
//// Tabs
5457
void on_Tabs_currentChanged(int); // tabs handling
5558

mainwindow.ui

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,9 @@ QToolTip {
540540
<property name="text">
541541
<string>Image file</string>
542542
</property>
543+
<property name="alignment">
544+
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
545+
</property>
543546
</widget>
544547
<widget class="QScrollBar" name="horizontalScrollBar_segmentation">
545548
<property name="geometry">
@@ -4309,6 +4312,55 @@ QToolTip {
43094312
</property>
43104313
</widget>
43114314
</widget>
4315+
<widget class="QPushButton" name="button_quit">
4316+
<property name="geometry">
4317+
<rect>
4318+
<x>1260</x>
4319+
<y>360</y>
4320+
<width>91</width>
4321+
<height>61</height>
4322+
</rect>
4323+
</property>
4324+
<property name="cursor">
4325+
<cursorShape>PointingHandCursor</cursorShape>
4326+
</property>
4327+
<property name="focusPolicy">
4328+
<enum>Qt::NoFocus</enum>
4329+
</property>
4330+
<property name="styleSheet">
4331+
<string notr="true">QPushButton {
4332+
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
4333+
stop: 0 #FFFFFF, stop: 1 #E0E0E0);
4334+
border-radius: 10px;
4335+
border: 2px outset #8f8f91;
4336+
color rgb(0,0,0);
4337+
}
4338+
QPushButton:pressed {
4339+
border: 2px inset #8f8f91;
4340+
}
4341+
QToolTip {
4342+
border:2px solid black;
4343+
padding:5px;
4344+
background-color:rgb(64,64,64);
4345+
color:white;
4346+
font-size: 14px;
4347+
}</string>
4348+
</property>
4349+
<property name="text">
4350+
<string>QUIT</string>
4351+
</property>
4352+
<property name="icon">
4353+
<iconset>
4354+
<normalon>:/icons/quit.png</normalon>
4355+
</iconset>
4356+
</property>
4357+
<property name="iconSize">
4358+
<size>
4359+
<width>32</width>
4360+
<height>32</height>
4361+
</size>
4362+
</property>
4363+
</widget>
43124364
<zorder>frame_zoom</zorder>
43134365
<zorder>label_segmentation</zorder>
43144366
<zorder>Tabs</zorder>
@@ -4319,6 +4371,7 @@ QToolTip {
43194371
<zorder>verticalScrollBar_segmentation</zorder>
43204372
<zorder>label_thumbnail</zorder>
43214373
<zorder>frame_about</zorder>
4374+
<zorder>button_quit</zorder>
43224375
</widget>
43234376
</widget>
43244377
<layoutdefault spacing="6" margin="11"/>

resources.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<file>./icons/mask.png</file>
2626
<file>./icons/normalize.png</file>
2727
<file>./icons/photoshop.png</file>
28+
<file>./icons/quit.png</file>
2829
<file>./icons/save.png</file>
2930
<file>./icons/session-load.png</file>
3031
<file>./icons/session-save.png</file>

0 commit comments

Comments
 (0)