Skip to content
Snippets Groups Projects
Commit 9f5496c7 authored by Mohammad Mahadi Hasan's avatar Mohammad Mahadi Hasan
Browse files

Added hyperlink style button for recent projects

parent 84fba295
No related branches found
No related tags found
No related merge requests found
#include "WelcomeView.h" #include "WelcomeView.h"
#include "qdebug.h"
#include <QGroupBox> #include <QGroupBox>
#include <QLabel> #include <QLabel>
#include <QComboBox> #include <QComboBox>
...@@ -51,8 +52,8 @@ WelcomeView::WelcomeView(MainWindow *parent) ...@@ -51,8 +52,8 @@ WelcomeView::WelcomeView(MainWindow *parent)
// font.setPointSize(12); // font.setPointSize(12);
// recentLabel->setFont(font); // recentLabel->setFont(font);
QVBoxLayout *recentProjectLayout = new QVBoxLayout; m_recentProjectLayout = new QVBoxLayout;
generateRecentProjectList(recentProjectLayout); //generateRecentProjectList();
...@@ -62,7 +63,7 @@ WelcomeView::WelcomeView(MainWindow *parent) ...@@ -62,7 +63,7 @@ WelcomeView::WelcomeView(MainWindow *parent)
// recentProjectPanel->addStretch(); // recentProjectPanel->addStretch();
QGroupBox *recentProjectsBox = new QGroupBox(tr("Recent Projects:")); QGroupBox *recentProjectsBox = new QGroupBox(tr("Recent Projects:"));
recentProjectsBox->setLayout(recentProjectLayout); recentProjectsBox->setLayout(m_recentProjectLayout);
QFrame* line = new QFrame(); QFrame* line = new QFrame();
line->setFrameShape(QFrame::VLine); line->setFrameShape(QFrame::VLine);
...@@ -79,10 +80,10 @@ WelcomeView::WelcomeView(MainWindow *parent) ...@@ -79,10 +80,10 @@ WelcomeView::WelcomeView(MainWindow *parent)
connect(newProjectButton, SIGNAL(clicked()), m_projectManager, SLOT(newProject())); connect(newProjectButton, SIGNAL(clicked()), m_projectManager, SLOT(newProject()));
connect(openProjectButton, SIGNAL(clicked()), m_projectManager, SLOT(openProject())); connect(openProjectButton, SIGNAL(clicked()), m_projectManager, SLOT(openProject()));
connect(newUsertButton, SIGNAL(clicked()), this, SLOT(onNewUser())); connect(newUsertButton, SIGNAL(clicked()), this, SLOT(onNewUser()));
} }
void WelcomeView::generateRecentProjectList(QVBoxLayout *layout) void WelcomeView::generateRecentProjectList()
{ {
/*m_recentProjectsMenu->clear(); /*m_recentProjectsMenu->clear();
...@@ -108,6 +109,7 @@ void WelcomeView::generateRecentProjectList(QVBoxLayout *layout) ...@@ -108,6 +109,7 @@ void WelcomeView::generateRecentProjectList(QVBoxLayout *layout)
bool hasRecentProjects = false; bool hasRecentProjects = false;
QCommandLinkButton *slotButtons[count]; QCommandLinkButton *slotButtons[count];
QLabel *myLabel[count];
m_signalMapper = new QSignalMapper(this); m_signalMapper = new QSignalMapper(this);
int i = 0; int i = 0;
...@@ -116,19 +118,41 @@ void WelcomeView::generateRecentProjectList(QVBoxLayout *layout) ...@@ -116,19 +118,41 @@ void WelcomeView::generateRecentProjectList(QVBoxLayout *layout)
slotButtons[i] = new QCommandLinkButton; slotButtons[i] = new QCommandLinkButton;
slotButtons[i]->setText(Utils::withTildeHomePath(file)); slotButtons[i]->setText(Utils::withTildeHomePath(file));
slotButtons[i]->setText("<a href=\"#\">Click Here!</a>");
//slotButtons[i]->setDescription("Recent description"); //slotButtons[i]->setDescription("Recent description");
slotButtons[i]->setFixedHeight(35); slotButtons[i]->setFixedHeight(35);
//m_signalMapper->setMapping(slotButtons[i], file);
//connect(slotButtons[i], SIGNAL(clicked()), m_signalMapper, SLOT (map()));
//m_recentProjectLayout->addWidget(slotButtons[i]);
m_signalMapper->setMapping(slotButtons[i], file); QFont font;
connect(slotButtons[i], SIGNAL(clicked()), font.setPointSize(10);
m_signalMapper, SLOT (map())); font.setBold(false);
//font.underline();
QString labelText;
labelText.append("<a href=\"#\" style=\"text-decoration:none;\">");
labelText.append( Utils::withTildeHomePath(file));
labelText.append("</a>");
myLabel[i] = new QLabel;
myLabel[i]->setText(labelText);
myLabel[i]->setTextFormat(Qt::RichText);
myLabel[i]->setTextInteractionFlags(Qt::TextBrowserInteraction);
//myLabel->setOpenExternalLinks(true);
myLabel[i]->setFont(font);
myLabel[i]->setFixedHeight(20);
m_signalMapper->setMapping(myLabel[i], file);
connect(myLabel[i], SIGNAL(linkActivated(QString)), m_signalMapper, SLOT (map()));
m_recentProjectLayout->addWidget(myLabel[i]);
layout->addWidget(slotButtons[i]);
i++; i++;
} }
layout->addStretch(); m_recentProjectLayout->addStretch();
connect(m_signalMapper, SIGNAL(mapped(QString)), connect(m_signalMapper, SIGNAL(mapped(QString)),
m_projectManager, SLOT(openProject(QString))); m_projectManager, SLOT(openProject(QString)));
...@@ -144,3 +168,29 @@ void WelcomeView::onNewUser() ...@@ -144,3 +168,29 @@ void WelcomeView::onNewUser()
QUrl url(tr("http://www.google.com")); QUrl url(tr("http://www.google.com"));
QDesktopServices::openUrl(url); QDesktopServices::openUrl(url);
} }
void WelcomeView::updateRecentProjectPanel()
{
qDebug() << "WelcomeView::updateRecentProjectPanel called";
this->clearLayout(m_recentProjectLayout);
this->generateRecentProjectList();
}
void WelcomeView::clearLayout(QLayout* layout, bool deleteWidgets)
{
if(layout)
{
while (QLayoutItem* item = layout->takeAt(0))
{
if (deleteWidgets)
{
if (QWidget* widget = item->widget())
delete widget;
}
if (QLayout* childLayout = item->layout())
clearLayout(childLayout, deleteWidgets);
delete item;
}
}
}
...@@ -24,6 +24,7 @@ public slots: ...@@ -24,6 +24,7 @@ public slots:
//void onNewProject(); //void onNewProject();
//void onOpenProject(); //void onOpenProject();
void onNewUser(); void onNewUser();
void updateRecentProjectPanel();
private: private:
QPushButton *newProjectButton; QPushButton *newProjectButton;
...@@ -31,8 +32,10 @@ private: ...@@ -31,8 +32,10 @@ private:
QPushButton *newUsertButton; QPushButton *newUsertButton;
MainWindow *m_mainWindow; MainWindow *m_mainWindow;
ProjectManager *m_projectManager; ProjectManager *m_projectManager;
void generateRecentProjectList(QVBoxLayout *layout); void generateRecentProjectList();
QSignalMapper *m_signalMapper; QSignalMapper *m_signalMapper;
QVBoxLayout *m_recentProjectLayout;
void clearLayout(QLayout* layout, bool deleteWidgets = true);
}; };
#endif // WELCOMEVIEW_H #endif // WELCOMEVIEW_H
...@@ -175,6 +175,10 @@ void MainWindow::onChangeTabWidget(int index) ...@@ -175,6 +175,10 @@ void MainWindow::onChangeTabWidget(int index)
updateSimModel(); updateSimModel();
m_simulationView->updateViewElements(); m_simulationView->updateViewElements();
} }
else if(index == WelcomeTab)
{
m_welcomeView->updateRecentProjectPanel();
}
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment