Files
yacreader/YACReader/goto_dialog.cpp
luisangelsm 83e1b88c2c
Some checks failed
Build / Initialization (push) Has been cancelled
Build / Code Format Validation (push) Has been cancelled
Build / Linux (Qt6) (push) Has been cancelled
Build / Linux (Qt6 + 7zip) (push) Has been cancelled
Build / macOS (Qt6 Universal) (push) Has been cancelled
Build / Windows x64 (Qt6) (push) Has been cancelled
Build / Windows ARM64 (Qt6) (push) Has been cancelled
Build / Docker amd64 Image (push) Has been cancelled
Build / Docker arm64 Image (push) Has been cancelled
Build / Publish Dev Builds (push) Has been cancelled
Build / Publish Release (push) Has been cancelled
Build / Publish YACReader10 Pre-release Builds (push) Has been cancelled
Replace goto.png with a themeable svg image
2026-03-17 19:35:30 +01:00

85 lines
2.0 KiB
C++

#include "goto_dialog.h"
#include <QHBoxLayout>
#include <QIntValidator>
#include <QVBoxLayout>
GoToDialog::GoToDialog(QWidget *parent)
: QDialog(parent)
{
setupUI();
initTheme(this);
}
void GoToDialog::setupUI()
{
textLabel = new QLabel(tr("Page : "));
pageNumber = new QLineEdit;
v = new QIntValidator(this);
v->setBottom(1);
pageNumber->setValidator(v);
textLabel->setBuddy(pageNumber);
textLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
accept = new QPushButton(tr("Go To"));
connect(accept, &QAbstractButton::clicked, this, &GoToDialog::goTo);
cancel = new QPushButton(tr("Cancel"));
connect(cancel, &QAbstractButton::clicked, this, &QWidget::close);
auto topLayout = new QHBoxLayout;
topLayout->addWidget(textLabel);
topLayout->addWidget(pageNumber);
auto bottomLayout = new QHBoxLayout;
bottomLayout->addStretch();
bottomLayout->addWidget(accept);
bottomLayout->addWidget(cancel);
auto mainLayout = new QVBoxLayout;
mainLayout->addWidget(numPagesLabel = new QLabel(tr("Total pages : ")));
mainLayout->addLayout(topLayout);
mainLayout->addStretch();
mainLayout->addLayout(bottomLayout);
auto imgMainLayout = new QHBoxLayout;
imgLabel = new QLabel();
imgMainLayout->addWidget(imgLabel);
imgMainLayout->addLayout(mainLayout);
setLayout(imgMainLayout);
setWindowTitle(tr("Go to..."));
setModal(true);
pageNumber->setFocusPolicy(Qt::StrongFocus);
pageNumber->setFocus();
}
void GoToDialog::goTo()
{
unsigned int page = pageNumber->text().toInt();
if (page >= 1 && page <= v->top()) {
emit goToPage(page - 1);
close();
}
}
void GoToDialog::setNumPages(unsigned int numPages)
{
numPagesLabel->setText(tr("Total pages : ") + QString::number(numPages));
v->setTop(numPages);
}
void GoToDialog::open()
{
pageNumber->clear();
pageNumber->setFocus();
QDialog::open();
}
void GoToDialog::applyTheme(const Theme &theme)
{
imgLabel->setPixmap(theme.dialogIcons.goToDialogIcon);
}