diff --git a/StreamControl/mainwindow.cpp b/StreamControl/mainwindow.cpp index cd77c4b..d4cfa19 100644 --- a/StreamControl/mainwindow.cpp +++ b/StreamControl/mainwindow.cpp @@ -52,6 +52,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "ScCompleter.h" #include "ScLineEdit.h" #include "ScComboBox.h" +#include "scimageselect.h" #include "scradiogroup.h" #include "sctsbutton.h" #include "scsetbutton.h" @@ -573,6 +574,15 @@ QString MainWindow::saveXML() { QDomText newItemt = doc.createTextNode(value); newItem.appendChild(newItemt); + } else if (wType == "imageSelect") { + QString imagePath = ((ScImageSelect*)widgetList[i.key()])->getSelectedImagePath(); + if (QDir::isRelativePath(imagePath)) { // Changes imagePath to be relative to outputPath instead of StreamControl path + QDir outputDir = QDir(settings["outputPath"]); + QString absImagePath = QDir(imagePath).absolutePath(); + imagePath = outputDir.relativeFilePath(absImagePath); + } + QDomText newItemt = doc.createTextNode(imagePath); + newItem.appendChild(newItemt); } else if (wType == "tweet") { QVector > urlArray = ((TwitterWidget*)widgetList[ i.key()])->getURLs(); @@ -839,6 +849,15 @@ QString MainWindow::saveJSON() { } else if (wType == "radioGroup") { QString value = ((ScRadioGroup*)widgetList[i.key()])->getCurrentRadio(); Obj[i.key()] = value; + } else if (wType == "imageSelect") { + QString imagePath = ((ScImageSelect*)widgetList[i.key()])->getSelectedImagePath(); + if (QDir::isRelativePath(imagePath)) { + QDir outputDir = QDir(settings["outputPath"]); + QString absImagePath = QDir(imagePath).absolutePath(); + Obj[i.key()] = outputDir.relativeFilePath(absImagePath); + } else { + Obj[i.key()] = imagePath; + } } else if (wType == "tweet") { QVector > urlArray = ((TwitterWidget*)widgetList[ i.key()])->getURLs(); @@ -1319,6 +1338,8 @@ void MainWindow::parseLayout(QDomElement element, QWidget *parent) { addRadioGroup(child.toElement(), parent); } else if (tagName == "comboBox") { addComboBox(child.toElement(), parent); + } else if (tagName == "imageSelect") { + addImageSelect(child.toElement(), parent); } else if (tagName == "tweet") { addTweetWidget(child.toElement(), parent); needLink = true; @@ -1887,6 +1908,24 @@ void MainWindow::addComboBox(QDomElement element, QWidget *parent) { } } +void MainWindow::addImageSelect(QDomElement element, QWidget *parent) { + QString newImageSelect = element.attribute("id"); + widgetType[newImageSelect] = "imageSelect"; + widgetList[newImageSelect] = new ScImageSelect(parent, + element.attribute("path"), + element.attribute("defaultValue"), + element.attribute("optionWidth").toInt(), + element.attribute("optionHeight").toInt(), + element.attribute("optionsColumns").toInt()); + widgetList[newImageSelect]->setObjectName(newImageSelect); + ((ScImageSelect*)widgetList[newImageSelect])->setGeometry(QRect(element.attribute("x").toInt(), + element.attribute("y").toInt(), + element.attribute("width").toInt(), + element.attribute("height").toInt())); + setWidgetFontSize((ScImageSelect*)widgetList[newImageSelect], element.attribute("fontSize", 0).toInt()); + ((ScImageSelect*)widgetList[newImageSelect])->setIconSize(((ScImageSelect*)widgetList[newImageSelect])->size()); +} + void MainWindow::addRadioGroup(QDomElement element, QWidget *parent) { QString newRadioGroup = element.attribute("id"); diff --git a/StreamControl/mainwindow.h b/StreamControl/mainwindow.h index c2f7614..21a7427 100644 --- a/StreamControl/mainwindow.h +++ b/StreamControl/mainwindow.h @@ -76,6 +76,7 @@ public slots: void addCheckBox(QDomElement, QWidget*); void addComboBox(QDomElement, QWidget*); void addRadioGroup(QDomElement, QWidget*); + void addImageSelect(QDomElement, QWidget*); void addTweetWidget(QDomElement, QWidget*); void addProviderWidget(QDomElement, QWidget*, QMap widgetList, ProviderWidgetBuilder::Provider); QString addTabWidget(QDomElement, QWidget*); diff --git a/StreamControl/scimageselect.cpp b/StreamControl/scimageselect.cpp new file mode 100644 index 0000000..28f8e3d --- /dev/null +++ b/StreamControl/scimageselect.cpp @@ -0,0 +1,71 @@ +#include +#include + +#include "scimageselect.h" + +ScImageSelect::ScImageSelect(QWidget *parent, QString path, QString defaultImageSubPath, int optionWidth, int optionHeight, int optionsColumns) : QPushButton(parent) +{ + this->path = path.endsWith('/') ? path : path + "/"; + if (!defaultImageSubPath.isEmpty()) { + this->selectedImagePath = this->path + defaultImageSubPath; + } + this->optionWidth = optionWidth; + this->optionHeight = optionHeight; + this->optionsColumns = optionsColumns; + this->setIcon(QIcon(this->selectedImagePath)); + optionsWidget = new QWidget(this->parentWidget()); + connect(this, SIGNAL(clicked()), this, SLOT(displayOptions())); +} + +void ScImageSelect::displayOptions() { + // if options are already displayed, hide them and return + if (!optionsWidget->findChildren().isEmpty()) { + qDeleteAll(optionsWidget->findChildren()); + return; + } + + qDeleteAll(optionsWidget->findChildren()); + QDir dir = QDir(path); + QStringList filters; + filters << "*.png" << "*.jpg" << "*.bmp"; + QStringList options = dir.entryList(filters, QDir::Files|QDir::NoDotAndDotDot); + for (int i = 0; i < options.size(); i++) { + QPushButton *optionButton = new QPushButton(optionsWidget); + optionButton->setGeometry(QRect(optionWidth * (i % 8), + optionHeight * (i/8), + optionWidth, + optionHeight)); + optionButton->setIcon(QIcon(path + options[i])); + optionButton->setIconSize(optionButton->size()); + optionButton->setObjectName(path + options[i]); + connect(optionButton, SIGNAL(clicked()), this, SLOT(selectOption())); + optionButton->show(); + } + optionsWidget->adjustSize(); + optionsWidget->move(this->geometry().center().x() - (optionsWidget->width() / 2), + this->geometry().bottom()); + optionsWidget->show(); +} + +void ScImageSelect::selectOption() { + selectedImagePath = sender()->objectName(); + this->setIcon(QIcon(selectedImagePath)); + qDeleteAll(optionsWidget->findChildren()); +} + +void ScImageSelect::setName(QString name, QString dataSetName) { + this->name = name; + this->dataSetName = dataSetName; +} + +QString ScImageSelect::getName() { + return name; +} + +QString ScImageSelect::getDataSetName() { + return dataSetName; +} + +QString ScImageSelect::getSelectedImagePath() { + return selectedImagePath; +} diff --git a/StreamControl/scimageselect.h b/StreamControl/scimageselect.h new file mode 100644 index 0000000..a559ac9 --- /dev/null +++ b/StreamControl/scimageselect.h @@ -0,0 +1,37 @@ +#ifndef SCIMAGESELECT_H +#define SCIMAGESELECT_H + +#include + +class QGridLayout; + +class ScImageSelect : public QPushButton +{ + Q_OBJECT + +public: + ScImageSelect(QWidget *parent = 0, QString path = "", QString defaultImage = "", int optionWidth = 32, int optionHeight = 32, int optionsColumns = 8); + +private slots: + void displayOptions(); + void selectOption(); + void setName(QString, QString); + +public slots: + QString getName(); + QString getDataSetName(); + QString getSelectedImagePath(); + +private: + QString name; + QString dataSetName; + QString path; + QWidget *optionsWidget; + int optionWidth; + int optionHeight; + int optionsColumns; + QString selectedImagePath; +}; + + +#endif // SCIMAGESELECT_H