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

#include "progressdialog.h"

ProgressDialog::ProgressDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){
    mSrc = new QLabel;
    mDst = new QLabel;
    mProgress = new QProgressBar;
    mSum = new QLabel(tr("Wait for it..."));
    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(mSrc);
    mainLayout->addWidget(mDst);
    mainLayout->addWidget(mProgress);
    mainLayout->addWidget(mSum);
    mainLayout->addLayout(btnLayout);
    setMaximumWidth(400);
    setMinimumWidth(400);
    setLayout(mainLayout);
}

void ProgressDialog::setLabelText(const QString &src, const QString &dst){
    QFontMetrics fm(mSrc->font());
    int width = mSrc->width() - 4;
    QString srcElided = fm.elidedText(src, Qt::ElideRight, width);
    mSrc->setText(srcElided);
    QString dstElided = fm.elidedText(dst, Qt::ElideRight, width);
    mDst->setText(dstElided);
}

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