From 83fba04a66b29dffc5467c493d9f00fffdac63b6 Mon Sep 17 00:00:00 2001 From: Brett Weir Date: Wed, 20 Jan 2016 01:48:43 -0800 Subject: [PATCH 1/2] New from template dialogs are mostly functional, but don't connect to anything yet (IDE-133) --- src/propelleride/forms/mainwindow.ui | 13 ++ src/propelleride/forms/newfromtemplate.ui | 72 ++++++++-- src/propelleride/forms/templateicon.ui | 161 ++++++++++++++++++++++ src/propelleride/mainwindow.cpp | 11 ++ src/propelleride/mainwindow.h | 1 + src/propelleride/newfromtemplate.cpp | 104 ++++++++++++++ src/propelleride/newfromtemplate.h | 41 ++++++ src/propelleride/propelleride.pro | 6 + src/propelleride/templateicon.cpp | 58 ++++++++ src/propelleride/templateicon.h | 30 ++++ 10 files changed, 488 insertions(+), 9 deletions(-) create mode 100644 src/propelleride/forms/templateicon.ui create mode 100644 src/propelleride/newfromtemplate.cpp create mode 100644 src/propelleride/newfromtemplate.h create mode 100644 src/propelleride/templateicon.cpp create mode 100644 src/propelleride/templateicon.h diff --git a/src/propelleride/forms/mainwindow.ui b/src/propelleride/forms/mainwindow.ui index e186609..ce50bf5 100644 --- a/src/propelleride/forms/mainwindow.ui +++ b/src/propelleride/forms/mainwindow.ui @@ -89,6 +89,8 @@ &File + + @@ -816,6 +818,17 @@ View the Propeller quick reference chart + + + New From &Template + + + Create a new file from a template + + + Ctrl+Shift+T + + diff --git a/src/propelleride/forms/newfromtemplate.ui b/src/propelleride/forms/newfromtemplate.ui index 645eff8..0a36f07 100644 --- a/src/propelleride/forms/newfromtemplate.ui +++ b/src/propelleride/forms/newfromtemplate.ui @@ -6,7 +6,7 @@ 0 0 - 612 + 590 363 @@ -36,11 +36,6 @@ false - - - Spin - - @@ -112,16 +107,75 @@ true - + 0 0 - 393 + 371 317 - buttonBox + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + + + 0 + 0 + + + + + + + + Qt::Vertical + + + + 20 + 138 + + + + + + + + + + Qt::Horizontal + + + + 344 + 20 + + + + + diff --git a/src/propelleride/forms/templateicon.ui b/src/propelleride/forms/templateicon.ui new file mode 100644 index 0000000..9985588 --- /dev/null +++ b/src/propelleride/forms/templateicon.ui @@ -0,0 +1,161 @@ + + + TemplateIcon + + + + 0 + 0 + 128 + 72 + + + + + 0 + 0 + + + + + 128 + 72 + + + + + + + + + 252 + 252 + 252 + + + + + + + 255 + 255 + 255 + + + + + + + + + 252 + 252 + 252 + + + + + + + 255 + 255 + 255 + + + + + + + + + 255 + 255 + 255 + + + + + + + 255 + 255 + 255 + + + + + + + + true + + + true + + + + 0 + + + 3 + + + 0 + + + 3 + + + 6 + + + + + + 0 + 1 + + + + + 48 + 48 + + + + + + + :/icons/icon.png + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + Supre Long Tiosjdf + + + Qt::AlignHCenter|Qt::AlignTop + + + true + + + + + + + + + + diff --git a/src/propelleride/mainwindow.cpp b/src/propelleride/mainwindow.cpp index fb1bb57..3b9b4ca 100644 --- a/src/propelleride/mainwindow.cpp +++ b/src/propelleride/mainwindow.cpp @@ -13,6 +13,8 @@ #include #include +#include "newfromtemplate.h" + #include "ui_about.h" MainWindow::MainWindow(QWidget *parent) @@ -45,6 +47,7 @@ MainWindow::MainWindow(QWidget *parent) // File Menu connect(ui.action_New,SIGNAL(triggered()),ui.editorTabs,SLOT(newFile())); + connect(ui.actionNew_From_Template,SIGNAL(triggered()),this,SLOT(newFromTemplate())); connect(ui.action_Open,SIGNAL(triggered()),ui.editorTabs,SLOT(open())); connect(ui.action_Save,SIGNAL(triggered()),ui.editorTabs,SLOT(save())); @@ -640,6 +643,14 @@ void MainWindow::about() about->show(); } +void MainWindow::newFromTemplate() +{ + getApplicationSettings(); + + NewFromTemplate * newfromtemplate = new NewFromTemplate(spinIncludes); + newfromtemplate->exec(); +} + void MainWindow::showMessage(const QString & message) { statusBar()->showMessage(message, 2000); diff --git a/src/propelleride/mainwindow.h b/src/propelleride/mainwindow.h index 047f2ce..0738f53 100644 --- a/src/propelleride/mainwindow.h +++ b/src/propelleride/mainwindow.h @@ -66,6 +66,7 @@ public slots: void propellerDatasheet(); void propellerQuickReference(); void about(); + void newFromTemplate(); void setProject(); diff --git a/src/propelleride/newfromtemplate.cpp b/src/propelleride/newfromtemplate.cpp new file mode 100644 index 0000000..cea83ff --- /dev/null +++ b/src/propelleride/newfromtemplate.cpp @@ -0,0 +1,104 @@ +#include "newfromtemplate.h" + +#include +#include + +NewFromTemplate::NewFromTemplate( + QStringList paths, + QWidget * parent) +: QDialog(parent) +{ + ui.setupUi(this); + layout = NULL; + + QStringList temps; + temps << "Basic_Terminal.spin" << "More_Files.spin" + << "Serial_Terminal.spin" + << "Serial_Terminal2.spin" + << "Serial_Terminal3.spin"; + + addTemplates("spin",temps); + + rebuildLayout(_templates[_category]); + +} + + +NewFromTemplate::~NewFromTemplate() +{ +} + +void NewFromTemplate::rebuildLayout(QList templates) +{ + if (layout != NULL) + { + foreach (TemplateIcon * t, templates) + { + layout->removeWidget(t); + } + delete layout; + } + + layout = new QGridLayout(); + layout->setSpacing(0); + layout->setContentsMargins(0,0,0,0); + ui.grid->setLayout(layout); + + layout->invalidate(); + + foreach (TemplateIcon * t, templates) + { + addWidget(t); + } + + layout->update(); +} + + +void NewFromTemplate::resizeEvent(QResizeEvent * e) +{ + Q_UNUSED(e); + qDebug() << "RESIZE"; + rebuildLayout(_templates[_category]); +} + +void NewFromTemplate::addWidget(QWidget * widget) +{ + int row = 0, col = 0; + int width = 0; + int newwidth = widget->geometry().width(); + + while (layout->itemAtPosition(row, col)) + { + width += layout->itemAtPosition(row, col)->geometry().width(); + + if (width + newwidth >= ui.scrollArea->width()) + { + width = 0; + col = 0; + row++; + } + else + { + col++; + } + } + + qDebug() << "ADD" << row << col << width + newwidth << ui.scrollArea->width(); + layout->addWidget(widget, row, col); +} + +void NewFromTemplate::addTemplates(QString category, QStringList templates) +{ + _category = category; + ui.listWidget->addItem(category); + + QList newtemplates; + + foreach (QString t, templates) + { + newtemplates.append(new TemplateIcon(t)); + } + + _templates[category] = newtemplates; +} diff --git a/src/propelleride/newfromtemplate.h b/src/propelleride/newfromtemplate.h new file mode 100644 index 0000000..55eb14a --- /dev/null +++ b/src/propelleride/newfromtemplate.h @@ -0,0 +1,41 @@ +#pragma once + +#include + +#include "ui_newfromtemplate.h" + +#include "templateicon.h" +#include "language.h" + +class NewFromTemplate : public QDialog +{ + Q_OBJECT + + Language language; + + QString _category; + QHash > _templates; + QGridLayout * layout; + + + + Ui::NewFromTemplate ui; + +private slots: + +public: + explicit NewFromTemplate( + QStringList paths = QStringList(), + QWidget * parent = 0); + ~NewFromTemplate(); + void addTemplates(QString category, QStringList templates); + +public slots: + +protected: + void resizeEvent(QResizeEvent * e); + +private: + void addWidget(QWidget * widget); + void rebuildLayout(QList templates); +}; diff --git a/src/propelleride/propelleride.pro b/src/propelleride/propelleride.pro index 8dc5bc3..82f1e9b 100644 --- a/src/propelleride/propelleride.pro +++ b/src/propelleride/propelleride.pro @@ -28,6 +28,8 @@ SOURCES += \ language.cpp \ main.cpp \ mainwindow.cpp \ + newfromtemplate.cpp \ + templateicon.cpp \ pathselector.cpp \ preferences.cpp \ logging.cpp \ @@ -43,6 +45,8 @@ HEADERS += \ highlighter.h \ language.h \ mainwindow.h \ + newfromtemplate.h \ + templateicon.h \ pathselector.h \ preferences.h \ templates/Singleton.h \ @@ -57,6 +61,8 @@ FORMS += \ forms/language.ui \ forms/finder.ui \ forms/buildmanager.ui \ + forms/newfromtemplate.ui \ + forms/templateicon.ui \ RESOURCES += \ fonts/fonts.qrc \ diff --git a/src/propelleride/templateicon.cpp b/src/propelleride/templateicon.cpp new file mode 100644 index 0000000..c108453 --- /dev/null +++ b/src/propelleride/templateicon.cpp @@ -0,0 +1,58 @@ +#include "templateicon.h" + +#include + +TemplateIcon::TemplateIcon(QString filename, + QIcon icon, + QWidget * parent) +: QWidget(parent) +{ + ui.setupUi(this); + + _filename = filename; + ui.filename->setText(filename.replace("_"," ").remove(".spin")); + _icon = icon; +} + +TemplateIcon::~TemplateIcon() +{ +} + +void TemplateIcon::enterEvent(QEvent * e) +{ + Q_UNUSED(e); + setColor(QColor("#97C9FD")); +} + +void TemplateIcon::leaveEvent(QEvent * e) +{ + Q_UNUSED(e); + setColor(QColor("#FFFFFF")); +} + + +void TemplateIcon::mousePressEvent(QMouseEvent * e) +{ + Q_UNUSED(e); + setColor(QColor("#2D83DE")); +} + +void TemplateIcon::mouseReleaseEvent(QMouseEvent * e) +{ + Q_UNUSED(e); + +} + +void TemplateIcon::mouseDoubleClickEvent(QMouseEvent * e) +{ + Q_UNUSED(e); + qDebug() << "DOUBLE CLICK" << _filename; + +} + +void TemplateIcon::setColor(QColor color) +{ + QPalette p = palette(); + p.setColor(QPalette::Window, color); + setPalette(p); +} diff --git a/src/propelleride/templateicon.h b/src/propelleride/templateicon.h new file mode 100644 index 0000000..2815e41 --- /dev/null +++ b/src/propelleride/templateicon.h @@ -0,0 +1,30 @@ +#pragma once + +#include "ui_templateicon.h" + +class TemplateIcon : public QWidget +{ + Q_OBJECT + + Ui::TemplateIcon ui; + + QString _filename; + QIcon _icon; + QColor _color; + +private slots: + +public: + explicit TemplateIcon(QString filename = QString(), QIcon icon = QIcon(), QWidget * parent = 0); + ~TemplateIcon(); + +public slots: + void setColor(QColor color); + +protected: + virtual void enterEvent(QEvent * e); + virtual void leaveEvent(QEvent * e); + virtual void mousePressEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void mouseDoubleClickEvent(QMouseEvent * e); +}; From b7fa079e303303c29b21a0e07688da805f644e53 Mon Sep 17 00:00:00 2001 From: Brett Weir Date: Thu, 21 Jan 2016 02:35:14 -0800 Subject: [PATCH 2/2] Completed New From Template (IDE-133) --- src/propelleride/filemanager.cpp | 52 +++++++++++++++++++++++ src/propelleride/filemanager.h | 2 + src/propelleride/forms/mainwindow.ui | 17 ++++++-- src/propelleride/forms/newfromtemplate.ui | 32 ++++++++------ src/propelleride/forms/templateicon.ui | 27 +++++++++--- src/propelleride/icons/icons.qrc | 1 + src/propelleride/mainwindow.cpp | 21 ++++++--- src/propelleride/newfromtemplate.cpp | 40 ++++++++++++----- src/propelleride/newfromtemplate.h | 4 +- src/propelleride/templateicon.cpp | 26 +++++++++--- src/propelleride/templateicon.h | 6 ++- 11 files changed, 177 insertions(+), 51 deletions(-) diff --git a/src/propelleride/filemanager.cpp b/src/propelleride/filemanager.cpp index ee73d1b..d3764c6 100644 --- a/src/propelleride/filemanager.cpp +++ b/src/propelleride/filemanager.cpp @@ -154,6 +154,58 @@ int FileManager::openFile(const QString & fileName) return 0; } + +void FileManager::newFromFile() +{ + QSettings settings; + settings.beginGroup("Paths"); + + QString lastDir = settings.value("lastDirectory", + QDir(tabToolTip(currentIndex())).path()).toString(); + + QString fileName = QFileDialog::getOpenFileName(this, + tr("New From File..."), lastDir, "Spin Files (*.spin);;All Files (*)"); + + if (!fileName.isEmpty()) + newFromFile(fileName); + + settings.endGroup(); +} + + +int FileManager::newFromFile(const QString & fileName) +{ + qCDebug(ideFileManager) << "newFromFile(" << fileName << ")"; + + if (fileName.isEmpty()) + return 1; + + QFile file(fileName); + if (!file.open(QFile::ReadOnly)) + { + QMessageBox::warning(this, tr("Warning"), + tr("Cannot read file %1:\n%2.") + .arg(fileName) + .arg(file.errorString())); + return 1; + } + + int index = newFile(); + + QTextStream in(&file); + in.setAutoDetectUnicode(true); + in.setCodec("UTF-8"); + getEditor(index)->setPlainText(reformatText(in.readAll())); + + getEditor(index)->saveContent(); + fileChanged(); + + emit fileUpdated(index); + + return 0; +} + + void FileManager::save() { save(currentIndex()); diff --git a/src/propelleride/filemanager.h b/src/propelleride/filemanager.h index 31b9f0a..47a401f 100644 --- a/src/propelleride/filemanager.h +++ b/src/propelleride/filemanager.h @@ -23,6 +23,8 @@ class FileManager : public QTabWidget public slots: int newFile(); + void newFromFile(); + int newFromFile(const QString & fileName); void open(); int openFile(const QString & fileName); void fileChanged(); diff --git a/src/propelleride/forms/mainwindow.ui b/src/propelleride/forms/mainwindow.ui index ce50bf5..1fb87b8 100644 --- a/src/propelleride/forms/mainwindow.ui +++ b/src/propelleride/forms/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 717 - 443 + 916 + 609 @@ -80,7 +80,7 @@ 0 0 - 717 + 916 28 @@ -90,6 +90,7 @@ + @@ -823,12 +824,20 @@ New From &Template - Create a new file from a template + Create a new file from a pre-defined template Ctrl+Shift+T + + + New From &File + + + Create a new file from an existing one + + diff --git a/src/propelleride/forms/newfromtemplate.ui b/src/propelleride/forms/newfromtemplate.ui index 0a36f07..3b3ada5 100644 --- a/src/propelleride/forms/newfromtemplate.ui +++ b/src/propelleride/forms/newfromtemplate.ui @@ -6,8 +6,8 @@ 0 0 - 590 - 363 + 526 + 378 @@ -112,8 +112,8 @@ 0 0 - 371 - 317 + 398 + 321 @@ -169,7 +169,7 @@ - 344 + 300 20 @@ -179,25 +179,29 @@ + + + + + + + + Click the language, then double-click to select a template. + + + - Qt::Vertical + Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Cancel - - - - Click the language, then double-click to select a template. - - - diff --git a/src/propelleride/forms/templateicon.ui b/src/propelleride/forms/templateicon.ui index 9985588..9b74aca 100644 --- a/src/propelleride/forms/templateicon.ui +++ b/src/propelleride/forms/templateicon.ui @@ -6,22 +6,28 @@ 0 0 - 128 - 72 + 100 + 94 - + 0 0 - 128 + 100 72 + + + 128 + 16777215 + + @@ -89,6 +95,9 @@ true + + Template + true @@ -136,13 +145,19 @@ - + 0 0 + + + 0 + 40 + + - Supre Long Tiosjdf + Template Qt::AlignHCenter|Qt::AlignTop diff --git a/src/propelleride/icons/icons.qrc b/src/propelleride/icons/icons.qrc index c67a973..a858c0d 100644 --- a/src/propelleride/icons/icons.qrc +++ b/src/propelleride/icons/icons.qrc @@ -14,6 +14,7 @@ edit-paste.png edit-redo.png edit-undo.png + edit-selectall.png file-archive.png file-close.png file-exit.png diff --git a/src/propelleride/mainwindow.cpp b/src/propelleride/mainwindow.cpp index 3b9b4ca..0090512 100644 --- a/src/propelleride/mainwindow.cpp +++ b/src/propelleride/mainwindow.cpp @@ -46,9 +46,10 @@ MainWindow::MainWindow(QWidget *parent) connect(ui.editorTabs, SIGNAL(fileUpdated(int)), this, SLOT(setProject())); // File Menu - connect(ui.action_New,SIGNAL(triggered()),ui.editorTabs,SLOT(newFile())); - connect(ui.actionNew_From_Template,SIGNAL(triggered()),this,SLOT(newFromTemplate())); - connect(ui.action_Open,SIGNAL(triggered()),ui.editorTabs,SLOT(open())); + connect(ui.action_New, SIGNAL(triggered()), ui.editorTabs, SLOT(newFile())); + connect(ui.actionNew_From_File, SIGNAL(triggered()), ui.editorTabs, SLOT(newFromFile())); + connect(ui.actionNew_From_Template, SIGNAL(triggered()), this, SLOT(newFromTemplate())); + connect(ui.action_Open, SIGNAL(triggered()), ui.editorTabs, SLOT(open())); connect(ui.action_Save,SIGNAL(triggered()),ui.editorTabs,SLOT(save())); connect(ui.actionSave_As,SIGNAL(triggered()),ui.editorTabs,SLOT(saveAs())); @@ -61,9 +62,9 @@ MainWindow::MainWindow(QWidget *parent) for (int i = 0; i < recentFiles.size(); i++) connect(recentFiles.at(i), SIGNAL(triggered()),this, SLOT(openRecentFile())); - connect(ui.action_Close, SIGNAL(triggered()), ui.editorTabs, SLOT(closeFile())); - connect(ui.actionClose_All, SIGNAL(triggered()), ui.editorTabs, SLOT(closeAll())); - connect(ui.action_Quit, SIGNAL(triggered()), this, SLOT(quitProgram())); + connect(ui.action_Close, SIGNAL(triggered()), ui.editorTabs, SLOT(closeFile())); + connect(ui.actionClose_All, SIGNAL(triggered()), ui.editorTabs, SLOT(closeAll())); + connect(ui.action_Quit, SIGNAL(triggered()), this, SLOT(quitProgram())); connect(ui.editorTabs, SIGNAL(saveAvailable(bool)), ui.action_Save, SLOT(setEnabled(bool))); connect(ui.editorTabs, SIGNAL(saveAvailable(bool)), ui.actionSave_All, SLOT(setEnabled(bool))); @@ -304,7 +305,7 @@ void MainWindow::setProject() addRecentFile(filename); parser->setFile(filename); parser->setLibraryPaths(spinIncludes); - qDebug() << spinIncludes; +// qDebug() << spinIncludes; recolorProjectView(); QApplication::restoreOverrideCursor(); @@ -649,6 +650,12 @@ void MainWindow::newFromTemplate() NewFromTemplate * newfromtemplate = new NewFromTemplate(spinIncludes); newfromtemplate->exec(); + + QString selected = newfromtemplate->selectedTemplate(); + if (!selected.isEmpty()) + ui.editorTabs->newFromFile(selected); + + delete newfromtemplate; } void MainWindow::showMessage(const QString & message) diff --git a/src/propelleride/newfromtemplate.cpp b/src/propelleride/newfromtemplate.cpp index cea83ff..bc00ecd 100644 --- a/src/propelleride/newfromtemplate.cpp +++ b/src/propelleride/newfromtemplate.cpp @@ -1,6 +1,7 @@ #include "newfromtemplate.h" #include +#include #include NewFromTemplate::NewFromTemplate( @@ -9,20 +10,26 @@ NewFromTemplate::NewFromTemplate( : QDialog(parent) { ui.setupUi(this); + layout = NULL; QStringList temps; - temps << "Basic_Terminal.spin" << "More_Files.spin" - << "Serial_Terminal.spin" - << "Serial_Terminal2.spin" - << "Serial_Terminal3.spin"; - addTemplates("spin",temps); + foreach (QString path, paths) + { + QDirIterator it(path + "/templates", QStringList() << "*.spin"); + while (it.hasNext()) + { + temps.append(it.next()); + } + } - rebuildLayout(_templates[_category]); + temps.sort(); -} + addTemplates("Spin",temps); + rebuildLayout(_templates[_category]); +} NewFromTemplate::~NewFromTemplate() { @@ -58,7 +65,6 @@ void NewFromTemplate::rebuildLayout(QList templates) void NewFromTemplate::resizeEvent(QResizeEvent * e) { Q_UNUSED(e); - qDebug() << "RESIZE"; rebuildLayout(_templates[_category]); } @@ -84,7 +90,6 @@ void NewFromTemplate::addWidget(QWidget * widget) } } - qDebug() << "ADD" << row << col << width + newwidth << ui.scrollArea->width(); layout->addWidget(widget, row, col); } @@ -97,8 +102,23 @@ void NewFromTemplate::addTemplates(QString category, QStringList templates) foreach (QString t, templates) { - newtemplates.append(new TemplateIcon(t)); + TemplateIcon * tmp = new TemplateIcon(t); + connect(tmp, SIGNAL(templateSelected(const QString &)), + this, SLOT(templateSelected(const QString &))); + newtemplates.append(tmp); } _templates[category] = newtemplates; } + + +QString NewFromTemplate::selectedTemplate() +{ + return _selected; +} + +void NewFromTemplate::templateSelected(const QString & filename) +{ + _selected = filename; + close(); +} diff --git a/src/propelleride/newfromtemplate.h b/src/propelleride/newfromtemplate.h index 55eb14a..3c93aa6 100644 --- a/src/propelleride/newfromtemplate.h +++ b/src/propelleride/newfromtemplate.h @@ -17,11 +17,12 @@ class NewFromTemplate : public QDialog QHash > _templates; QGridLayout * layout; - + QString _selected; Ui::NewFromTemplate ui; private slots: + void templateSelected(const QString & filename); public: explicit NewFromTemplate( @@ -29,6 +30,7 @@ private slots: QWidget * parent = 0); ~NewFromTemplate(); void addTemplates(QString category, QStringList templates); + QString selectedTemplate(); public slots: diff --git a/src/propelleride/templateicon.cpp b/src/propelleride/templateicon.cpp index c108453..cd1fb03 100644 --- a/src/propelleride/templateicon.cpp +++ b/src/propelleride/templateicon.cpp @@ -1,17 +1,30 @@ #include "templateicon.h" #include +#include TemplateIcon::TemplateIcon(QString filename, - QIcon icon, QWidget * parent) : QWidget(parent) { ui.setupUi(this); _filename = filename; - ui.filename->setText(filename.replace("_"," ").remove(".spin")); - _icon = icon; + + QFileInfo fi(filename); + + ui.filename->setText(fi.fileName().replace("_"," ").remove(".spin")); + + QString imagename = fi.absolutePath() + "/" + fi.completeBaseName() + ".png"; + + if (QFileInfo(imagename).exists()) + { + QImage image(imagename); + image = image.scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation); + ui.icon->setPixmap(QPixmap::fromImage(image)); + } + else + ui.icon->setPixmap(QPixmap(":/icons/edit-selectall.png")); } TemplateIcon::~TemplateIcon() @@ -30,7 +43,6 @@ void TemplateIcon::leaveEvent(QEvent * e) setColor(QColor("#FFFFFF")); } - void TemplateIcon::mousePressEvent(QMouseEvent * e) { Q_UNUSED(e); @@ -40,14 +52,14 @@ void TemplateIcon::mousePressEvent(QMouseEvent * e) void TemplateIcon::mouseReleaseEvent(QMouseEvent * e) { Q_UNUSED(e); - + setColor(QColor("#97C9FD")); } void TemplateIcon::mouseDoubleClickEvent(QMouseEvent * e) { Q_UNUSED(e); - qDebug() << "DOUBLE CLICK" << _filename; - + setColor(QColor("#2D83DE")); + emit templateSelected(_filename); } void TemplateIcon::setColor(QColor color) diff --git a/src/propelleride/templateicon.h b/src/propelleride/templateicon.h index 2815e41..6450b6f 100644 --- a/src/propelleride/templateicon.h +++ b/src/propelleride/templateicon.h @@ -9,13 +9,12 @@ class TemplateIcon : public QWidget Ui::TemplateIcon ui; QString _filename; - QIcon _icon; QColor _color; private slots: public: - explicit TemplateIcon(QString filename = QString(), QIcon icon = QIcon(), QWidget * parent = 0); + explicit TemplateIcon(QString filename = QString(), QWidget * parent = 0); ~TemplateIcon(); public slots: @@ -27,4 +26,7 @@ public slots: virtual void mousePressEvent(QMouseEvent * e); virtual void mouseReleaseEvent(QMouseEvent * e); virtual void mouseDoubleClickEvent(QMouseEvent * e); + +signals: + void templateSelected(const QString & filename); };