summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Studio/_Win/UI/StartupDlg.cpp
blob: 5d14356308754233885e403f3e22078ddfda66f1 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/****************************************************************************
**
** Copyright (C) 2006 NVIDIA Corporation.
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

//==============================================================================
// Prefix
//==============================================================================
#include "stdafx.h"
#include "StudioDefs.h"

//==============================================================================
// Includes
//==============================================================================

#include "StartupDlg.h"
#include "StudioUtils.h"
#include "StudioPreferences.h"
#include "ui_StartupDlg.h"

#include <QtCore/qfileinfo.h>
#include <QtGui/qpalette.h>
#include <QtCore/qdatetime.h>
#include <QtCore/qdir.h>

// CStartupDlg dialog

CStartupDlg::CStartupDlg(QWidget *pParent)
    : QDialog(pParent, Qt::MSWindowsFixedSizeDialogHint)
    , m_Choice(EStartupChoice_Invalid)
    , m_RecentDocSelected("")
    , m_ui(new Ui::StartupDlg)
    , m_palette(nullptr)
{
    m_ui->setupUi(this);
}

CStartupDlg::~CStartupDlg()
{
    delete m_palette;
}

static QString GetFileTimeReadable(const Qt3DSFile &inFile)
{
    QFileInfo finfo(inFile.GetAbsolutePath().toQString());
    if (!finfo.exists())
        return {};

    return finfo.lastModified().toString("MM/dd/yyyy");
}

void CStartupDlg::showEvent(QShowEvent *ev)
{
    OnInitDialog();
    QDialog::showEvent(ev);
}

void CStartupDlg::reject()
{
    m_Choice = EStartupChoice_Exit;
    QDialog::reject();
}

void CStartupDlg::OnInitDialog()
{
    QWidget *p = qobject_cast<QWidget *>(parent());
    if (p) {
        QRect pRect;
        if (p->isMaximized())
            pRect = QRect(QPoint(0, 0), GetAvailableDisplaySize(getWidgetScreen(p)));
        else
            pRect = p->frameGeometry();

        move(pRect.x() + pRect.width() / 2 - width() / 2,
             pRect.y() + pRect.height() / 2 - height() / 2);
    }

    connect(m_ui->newDocument, &ClickableLabel::clicked, this, &CStartupDlg::OnNewDocClicked);
    connect(m_ui->openDocument, &ClickableLabel::clicked, this, &CStartupDlg::OnOpenDocClicked);

    // Load the product version
    m_ProductVersionStr = QStringLiteral("Qt 3D Studio v")
            + CStudioPreferences::GetVersionString().toQString();
    m_ui->versionStr->setText(m_ProductVersionStr);

    // Populate the recent document list
    for (uint theIndex = 0; theIndex < RECENT_COUNT; ++theIndex) {
        ClickableLabel *recent
                = findChild<ClickableLabel *>(QStringLiteral("recent%1").arg(theIndex));
        connect(recent, &ClickableLabel::clicked, this, &CStartupDlg::OnStnClickedStartupRecent);

        recent->setProperty("recentIndex", theIndex);

        if (m_RecentDocs.size() > theIndex) {
            // Set the name
            recent->setText(m_RecentDocs[theIndex].GetName().toQString());
            // Set path and date to tooltip
            QFileInfo thePath(m_RecentDocs[theIndex].GetAbsolutePath().toQString());
            QString toolTip = thePath.absoluteDir().path();
            toolTip.append(QStringLiteral("\n"));
            toolTip.append(GetFileTimeReadable(m_RecentDocs[theIndex]));
            recent->setToolTip(toolTip);
        } else {
            recent->setEnabled(false);
            recent->setText(QString());
        }
    }
}

void CStartupDlg::AddRecentItem(const Qt3DSFile &inRecentItem)
{
    m_RecentDocs.push_back(inRecentItem);
}

CStartupDlg::EStartupChoice CStartupDlg::GetChoice()
{
    return m_Choice;
}

Qt3DSFile CStartupDlg::GetRecentDoc() const
{
    return m_RecentDocSelected;
}

void CStartupDlg::OnNewDocClicked()
{
    m_Choice = EStartupChoice_NewDoc;
    QDialog::accept();
}

void CStartupDlg::OnOpenDocClicked()
{
    m_Choice = EStartupChoice_OpenDoc;
    QDialog::accept();
}

void CStartupDlg::OnStnClickedStartupRecent()
{
    const int index = sender()->property("recentIndex").toInt();
    OpenRecent(index);
}

void CStartupDlg::OpenRecent(size_t inIndex)
{
    if (inIndex < m_RecentDocs.size()) {
        m_RecentDocSelected = m_RecentDocs[inIndex];
        m_Choice = EStartupChoice_OpenRecent;
        QDialog::accept();
    }
}

void CStartupDlg::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event)
    QPixmap pic = QPixmap(":/startup/open_dialog.png");
    pic.setDevicePixelRatio(devicePixelRatio());

    if (!m_palette) {
        m_palette = new QPalette;
        m_palette->setBrush(QPalette::Window, pic);
        setPalette(*m_palette);
    }

    resize(pic.size());
    setFixedSize(size());
}