summaryrefslogtreecommitdiff
path: root/src/main-view/WelcomeScreen.cpp
blob: 806a57af1fafcb8fa39a1897343d8ca698918627 (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
#include "WelcomeScreen.h"

WelcomeScreen::WelcomeScreen(QWidget* parent):
    QWidget(parent)
{
    QPushButton* newButton = createWelcomeButton("filenew",
        tr("Create new dictionary"), SLOT(newFile()));
    QPushButton* openButton = createWelcomeButton("fileopen",
        tr("Open existing dictionary"), SLOT(openFileWithDialog()));
    QPushButton* openExampleButton = createWelcomeButton("",
        tr("Open online dictionaries"), SLOT(openOnlineDictionaries()));
    QPushButton* importButton = createWelcomeButton("",
        tr("Import from CSV file"), SLOT(importFromCsv()));
    recentFilesButton = createWelcomeButton("",
        tr("Recent dictionaries"), NULL);

    QVBoxLayout* buttonsLt = new QVBoxLayout;
    buttonsLt->addWidget(newButton);
    buttonsLt->addWidget(openButton);
    buttonsLt->addWidget(openExampleButton);
    buttonsLt->addWidget(importButton);
    buttonsLt->addWidget(recentFilesButton);

    QGridLayout* paddingLt = new QGridLayout;
    paddingLt->addLayout(buttonsLt, 1, 1);
    setLayout(paddingLt);
}

QPushButton* WelcomeScreen::createWelcomeButton(const QString& iconName,
    const QString& text, const char* slot)
{
    static const QSize ButtonSize(350, 50);
    QPushButton* button = new QPushButton(QIcon(QString(":/images/%1.png").
        arg(iconName)), text);
    button->setMaximumSize(ButtonSize);
    if(slot)
        connect(button, SIGNAL(clicked()), parentWidget(), slot);
    return button;
}

void WelcomeScreen::updateRecentFilesButton()
{
    recentFilesButton->setEnabled(recentFilesButton->menu() &&
        !recentFilesButton->menu()->actions().isEmpty());
}

void WelcomeScreen::setRecentFilesMenu(QMenu* menu)
{
    recentFilesButton->setMenu(menu);
    updateRecentFilesButton();
}