summaryrefslogtreecommitdiffstats
path: root/progressdialog.cpp
blob: f354a07b36b313c1197632cd926fe102d47f601f (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
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>

#include "progressdialog.h"

ProgressDialog::ProgressDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){
    mLabel = new QLabel;
    mProgress = new QProgressBar;
    QPushButton *cancelBtn = new QPushButton(tr("Cancel"));
    connect(cancelBtn, SIGNAL(clicked()), this, SIGNAL(cancelled()));
    QHBoxLayout *btnLayout = new QHBoxLayout;
    btnLayout->addStretch();
    btnLayout->addWidget(cancelBtn);
    btnLayout->addStretch();
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(mLabel);
    mainLayout->addWidget(mProgress);
    mainLayout->addLayout(btnLayout);
    setMaximumWidth(400);
    setMinimumWidth(400);
    setLayout(mainLayout);
}

void ProgressDialog::setLabelText(const QString &text){
    QFontMetrics fm(mLabel->font());
    int width = mLabel->width() - 4;
    QString fixed = fm.elidedText(text, Qt::ElideRight, width);
    mLabel->setText(fixed);
}

void ProgressDialog::setValue(int val){
    mProgress->setValue(val);
}