ui: Startscreen Messagebox to delete missing coatiprojectfiles

This commit is contained in:
Andreas Stallinger
2016-04-12 14:13:15 +02:00
parent b088ca6adf
commit 4eef42d15c
3 changed files with 100 additions and 18 deletions
+8 -1
View File
@@ -20,7 +20,14 @@
font-size: 12pt;
}
#recentButton:hover {
#recentButtonMissing {
background: none;
border: none;
color: grey;
font-size: 12pt;
}
#recentButton:hover, #recentButtonMissing:hover {
background-color: #CFD2E0;
border-radius: 10px;
}
+84 -13
View File
@@ -4,6 +4,7 @@
#include <QString>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QMessageBox>
#include "settings/ApplicationSettings.h"
#include "utility/file/FileSystem.h"
@@ -12,14 +13,25 @@
#include "qt/utility/QtDeviceScaledPixmap.h"
#include "qt/utility/utilityQt.h"
#include "utility/logging/logging.h"
#include "isTrial.h"
QtRecentProjectButton::QtRecentProjectButton(const FilePath& projectFilePath, QWidget* parent)
QtRecentProjectButton::QtRecentProjectButton(QWidget* parent)
: QPushButton(parent)
, m_projectFilePath(projectFilePath)
{
}
bool QtRecentProjectButton::projectExists() const
{
return m_projectExists;
}
void QtRecentProjectButton::setProjectPath(const FilePath& projectFilePath)
{
m_projectFilePath = projectFilePath;
m_projectExists = projectFilePath.exists();
this->setText(m_projectFilePath.withoutExtension().fileName().c_str());
if ( projectFilePath.exists() )
if ( m_projectExists )
{
this->setToolTip(m_projectFilePath.str().c_str());
}
@@ -27,13 +39,39 @@ QtRecentProjectButton::QtRecentProjectButton(const FilePath& projectFilePath, QW
{
std::string missingFileText = "Couldn't find " + m_projectFilePath.str() + " in your filesystem";
this->setToolTip(missingFileText.c_str());
this->setEnabled(false);
}
}
void QtRecentProjectButton::handleButtonClick()
{
MessageLoadProject(m_projectFilePath.str(), false).dispatch();
if ( m_projectExists )
{
MessageLoadProject(m_projectFilePath.str(), false).dispatch();
}
else
{
std::string text = "Couldn't find " + m_projectFilePath.str()
+ " in your filesystem. Delete it from this recent Proejct list?";
int ret = QMessageBox::question(this, "Missing Project File", text.c_str(), QMessageBox::Yes | QMessageBox::No);
if ( ret == QMessageBox::Yes )
{
std::vector<FilePath> recentProjects = ApplicationSettings::getInstance()->getRecentProjects();
for (int i = 0
; i < ApplicationSettings::getInstance()->getMaxRecentProjectsCount()
; i++)
{
if (recentProjects[i].str() == m_projectFilePath.str() )
{
recentProjects.erase(recentProjects.begin()+i);
ApplicationSettings::getInstance()->setRecentProjects(recentProjects);
ApplicationSettings::getInstance()->save();
break;
}
}
emit updateButtons();
}
}
};
@@ -48,10 +86,42 @@ QSize QtStartScreen::sizeHint() const
return QSize(570, 600);
}
void QtStartScreen::updateButtons()
{
std::vector<FilePath> recentProjects = ApplicationSettings::getInstance()->getRecentProjects();
size_t i = 0;
for ( QtRecentProjectButton* button : m_recentProjectsButtons )
{
button->disconnect();
if (i < recentProjects.size())
{
button->setProjectPath(recentProjects[i]);
button->setFixedWidth(button->fontMetrics().width(button->text()) + 45);
connect(button, SIGNAL(clicked()), button, SLOT(handleButtonClick()));
//button->setGeometry(292, button->pos().y(), button->fontMetrics().width(button->text()) + 45, 40);
if (button->projectExists())
{
button->setObjectName("recentButton");
connect(button, SIGNAL(clicked()), this, SLOT(handleRecentButton()));
}
else
{
connect(button, SIGNAL(updateButtons()), this, SLOT(updateButtons()));
button->setObjectName("recentButtonMissing");
}
}
else
{
button->hide();
}
i++;
}
setStyleSheet(utility::getStyleSheet(ResourcePaths::getGuiPath() + "startscreen/startscreen.css").c_str());
}
void QtStartScreen::setupStartScreen()
{
setStyleSheet(utility::getStyleSheet(ResourcePaths::getGuiPath() + "startscreen/startscreen.css").c_str());
addLogo();
if (!isTrial())
@@ -78,21 +148,22 @@ void QtStartScreen::setupStartScreen()
int position = 290;
QIcon cpp_icon((ResourcePaths::getGuiPath() + "icon/project_256_256.png").c_str());
std::vector<FilePath> recentProjects = ApplicationSettings::getInstance()->getRecentProjects();
for (size_t i = 0; i < recentProjects.size() && (int)i < ApplicationSettings::getInstance()->getMaxRecentProjectsCount(); i++)
for (int i = 0
; i < ApplicationSettings::getInstance()->getMaxRecentProjectsCount()
; i++)
{
QtRecentProjectButton* button = new QtRecentProjectButton(recentProjects[i], this);
QtRecentProjectButton* button = new QtRecentProjectButton(this);
button->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
button->setIcon(cpp_icon);
button->setIconSize(QSize(25, 25));
button->setObjectName("recentButton");
button->minimumSizeHint(); // force font loading
button->setObjectName("recentButtonMissing");
button->setGeometry(292, position, button->fontMetrics().width(button->text()) + 45, 40);
button->minimumSizeHint(); // force font loading
button->show();
connect(button, SIGNAL(clicked()), button, SLOT(handleButtonClick()));
connect(button, SIGNAL(clicked()), this, SLOT(handleRecentButton()));
position += 40;
m_recentProjectsButtons.push_back(button);
}
updateButtons();
}
void QtStartScreen::handleNewProjectButton()
+8 -4
View File
@@ -12,12 +12,15 @@ class QtRecentProjectButton
Q_OBJECT
public:
QtRecentProjectButton(const FilePath& projectFilePath, QWidget* parent);
QtRecentProjectButton(QWidget* parent);
bool projectExists() const;
void setProjectPath(const FilePath& projectFilePath);
public slots:
void handleButtonClick();
signals:
void updateButtons();
private:
bool m_projectExists;
FilePath m_projectFilePath;
};
@@ -41,11 +44,12 @@ private slots:
void handleNewProjectButton();
void handleOpenProjectButton();
void handleRecentButton();
void updateButtons();
private:
QPushButton* m_openProjectButton;
QPushButton* m_newProjectButton;
std::vector<QPushButton*> m_recentProjects;
std::vector<QtRecentProjectButton*> m_recentProjectsButtons;
};
#endif // QT_START_SCREEN_H