summaryrefslogtreecommitdiffstats
path: root/sminputdialog.cpp
blob: ecd43c27177fc98f6157fd90a7146b8644c69b9b (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
#include <QLabel>
#include <QPushButton>
#include <QCompleter>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QStringListModel>

#include "sminputdialog.h"

SmInputDialog::SmInputDialog(const QString &label, QWidget *parent) : QDialog(parent){
    QLabel *thisL = new QLabel(label);
    mLE = new QLineEdit;
    mCompleter = new QCompleter(this);
    mLE->setCompleter(mCompleter);
    QPushButton *cancelPB = new QPushButton(tr("Cancel"));
    connect(cancelPB, &QPushButton::clicked, this, &SmInputDialog::reject);
    QPushButton *acceptPB = new QPushButton(tr("OK"));
    connect(acceptPB, &QPushButton::clicked, this, &SmInputDialog::accept);
    QHBoxLayout *topL = new QHBoxLayout;
    topL->addWidget(thisL);
    topL->addWidget(mLE);
    QHBoxLayout *buttonLayout = new QHBoxLayout;
    buttonLayout->addStretch();
    buttonLayout->addWidget(cancelPB);
    buttonLayout->addWidget(acceptPB);
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addLayout(topL);
    mainLayout->addLayout(buttonLayout);
    setLayout(mainLayout);
}

void SmInputDialog::setText(QString &text){
    mLE->setText(text);
}

void SmInputDialog::setCompleterModel(const QStringList &model){
    mCompleter->setModel(new QStringListModel(model));
}