Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added welcome screen #1374

Merged
merged 8 commits into from
Oct 19, 2023
65 changes: 48 additions & 17 deletions launcher/ui/instanceview/InstanceView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,32 @@

#include "InstanceView.h"

#include <QPainter>
#include <QAccessible>
#include <QApplication>
#include <QtMath>
#include <QMouseEvent>
#include <QListView>
#include <QPersistentModelIndex>
#include <QCache>
#include <QDrag>
#include <QFont>
#include <QListView>
#include <QMimeData>
#include <QCache>
#include <QMouseEvent>
#include <QPainter>
#include <QPersistentModelIndex>
#include <QScrollBar>
#include <QAccessible>
#include <QtMath>

#include <QDebug>
#include <cstddef>
#include "VisualGroup.h"
#include "ui/themes/ThemeManager.h"
#include <QDebug>

#include <Application.h>
#include <InstanceList.h>


template <typename T> bool listsIntersect(const QList<T> &l1, const QList<T> t2)
template <typename T>
bool listsIntersect(const QList<T>& l1, const QList<T> t2)
{
for (auto &item : l1)
{
if (t2.contains(item))
{
for (auto& item : l1) {
if (t2.contains(item)) {
return true;
}
}
Expand Down Expand Up @@ -536,11 +536,42 @@ void InstanceView::paintEvent(QPaintEvent* event)
#endif
option.widget = this;

if (model()->rowCount() == 0) {
painter.save();
const QString line1 = "Welcome!";
const QString line2 = "Add an instance to get started.";
Trial97 marked this conversation as resolved.
Show resolved Hide resolved
auto rect = this->viewport()->rect();
auto font = option.font;
font.setPointSize(53);
painter.setFont(font);
auto fm = painter.fontMetrics();

if (rect.height() <= (fm.height() * 5) || rect.width() <= fm.horizontalAdvance(line2)) {
auto s = rect.height() / (5. * fm.height());
auto sx = rect.width() * 1. / fm.horizontalAdvance(line2);
if (s >= sx)
s = sx;
auto ps = font.pointSize() * s;
if (ps <= 0)
ps = 1;
font.setPointSize(ps);
painter.setFont(font);
fm = painter.fontMetrics();
}

// text
rect.setTop(rect.top() + fm.height() * 1.5);
painter.drawText(rect, Qt::AlignHCenter, line1);
rect.setTop(rect.top() + fm.height());
painter.drawText(rect, Qt::AlignHCenter, line2);
painter.restore();
return;
}

int wpWidth = viewport()->width();
option.rect.setWidth(wpWidth);
for (int i = 0; i < m_groups.size(); ++i)
{
VisualGroup *category = m_groups.at(i);
for (int i = 0; i < m_groups.size(); ++i) {
VisualGroup* category = m_groups.at(i);
int y = category->verticalPosition();
y -= verticalOffset();
QRect backup = option.rect;
Expand Down