Skip to content

Commit

Permalink
Refs issue #43: removed duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-Amadeus committed Jun 11, 2018
1 parent f39758d commit 28e9e78
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
35 changes: 14 additions & 21 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ MainWindow::MainWindow(QWidget *parent, MolluscPalette* molluscPalette, bool use
m_countdownLabel->setStyleSheet("QLabel { background-color : black; color : white; font}");
m_mainLayout->addWidget(m_countdownLabel, 0, 0, 4, 3, Qt::AlignCenter);

this->showCameraButton();
this->initButtons();
this->showDia();
}

Expand Down Expand Up @@ -230,31 +230,24 @@ void MainWindow::showSidebar(
this->addDockWidget(Qt::RightDockWidgetArea, m_dWidget);
}

void MainWindow::showCameraButton() {
const auto iconSize = 100;
void MainWindow::initButton(QPushButton* button, std::string icon, int row, int column, bool visible) {
const int iconSize = 100;
button->setIcon(QIcon(m_data + "/" + icon.c_str()));
button->setIconSize(QSize(iconSize, iconSize));
button->setFixedSize(iconSize, iconSize);
button->setStyleSheet("text-align:center; background: black; border: none");
button->setVisible(visible);
m_mainLayout->addWidget(button, row, column);
}

m_backButton->setIcon(QIcon(m_data + "/back.png"));
m_backButton->setIconSize(QSize(iconSize, iconSize));
m_backButton->setMaximumSize(iconSize, iconSize);
m_backButton->setStyleSheet("text-align:center; background: black; border: none");
m_backButton->setVisible(false);
m_mainLayout->addWidget(m_backButton, 0, 0);
void MainWindow::initButtons() {
initButton(m_backButton, "back.png", 0, 0, false);
connect(m_backButton, SIGNAL(released()), this, SLOT(showDia()));

m_shareButton->setIcon(QIcon(m_data + "/share.png"));
m_shareButton->setIconSize(QSize(iconSize, iconSize));
m_shareButton->setMaximumSize(iconSize, iconSize);
m_shareButton->setStyleSheet("text-align:center; background: black; border: none");
m_shareButton->setVisible(false);
m_mainLayout->addWidget(m_shareButton, 2, 2);
initButton(m_shareButton, "share.png", 2, 2, false);
connect(m_shareButton, SIGNAL(released()), this, SLOT(shareButtonClick()));

m_cameraButton->setIcon(QIcon(m_data + "/camera.png"));
m_cameraButton->setIconSize(QSize(iconSize, iconSize));
m_cameraButton->setMaximumSize(iconSize, iconSize);
m_cameraButton->setStyleSheet("text-align:center; background: black; border: none");
m_shareButton->setVisible(true);
m_mainLayout->addWidget(m_cameraButton, 3, 2);
initButton(m_cameraButton, "camera.png", 3, 2);
connect(m_cameraButton, SIGNAL(released()), this, SLOT(takeSelfie()));
}

Expand Down
3 changes: 2 additions & 1 deletion src/mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class MainWindow : public QMainWindow {
void sendMail();
void keyPressEvent(QKeyEvent* event);
void showSnailInfo();
void showCameraButton();
void showSidebar(const QString &classContent,
const QString &familyContent,
const QString &genusContent,
Expand Down Expand Up @@ -104,6 +103,8 @@ class MainWindow : public QMainWindow {

void takePicture();
void stopDia();
void initButton(QPushButton* button, std::string icon, int row, int column, bool visible = true);
void initButtons();
void processAndShowPicture(std::shared_ptr<QImage> image);

public slots:
Expand Down

0 comments on commit 28e9e78

Please sign in to comment.