summaryrefslogtreecommitdiff
path: root/src/previewdialog.cpp
blob: 06dcd6746f1f9e21f17af4e8bd769d6f850f2111 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "previewdialog.h"
#include "ui_previewdialog.h"
#include "settings.h"
#include <QFileInfo>

PreviewDialog::PreviewDialog(const QString &fileName, QWidget *parent) :
  QDialog(parent),
  ui(new Ui::PreviewDialog)
{
  ui->setupUi(this);
  ui->nameLabel->setText(QFileInfo(fileName).fileName());
  ui->nextButton->setEnabled(false);
  ui->previousButton->setEnabled(false);
}

PreviewDialog::~PreviewDialog()
{
  delete ui;
}

int PreviewDialog::exec()
{
  auto& settings = Settings::instance();

  if (auto v=settings.geometry().getPreviewDialog()) {
    restoreGeometry(*v);
  }

  const int r = QDialog::exec();

  settings.geometry().setPreviewDialog(saveGeometry());

  return r;
}

void PreviewDialog::addVariant(const QString &modName, QWidget *widget)
{
  widget->setProperty("modName", modName);
  ui->variantsStack->addWidget(widget);
  if (ui->variantsStack->count() > 1) {
    ui->nextButton->setEnabled(true);
    ui->previousButton->setEnabled(true);
  }
}

int PreviewDialog::numVariants() const
{
  return ui->variantsStack->count();
}

void PreviewDialog::on_variantsStack_currentChanged(int index)
{
  ui->modLabel->setText(ui->variantsStack->widget(index)->property("modName").toString());
}

void PreviewDialog::on_closeButton_clicked()
{
  this->accept();
}

void PreviewDialog::on_previousButton_clicked()
{
  int i = ui->variantsStack->currentIndex() - 1;
  if (i < 0) {
    i = ui->variantsStack->count() - 1;
  }
  ui->variantsStack->setCurrentIndex(i);
}

void PreviewDialog::on_nextButton_clicked()
{
  ui->variantsStack->setCurrentIndex((ui->variantsStack->currentIndex() + 1) % ui->variantsStack->count());
}