Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions StreamControl/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<QMap<QString,QString> > urlArray = ((TwitterWidget*)widgetList[
i.key()])->getURLs();
Expand Down Expand Up @@ -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<QMap<QString,QString> > urlArray = ((TwitterWidget*)widgetList[
i.key()])->getURLs();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions StreamControl/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QString, QObject*> widgetList, ProviderWidgetBuilder::Provider);
QString addTabWidget(QDomElement, QWidget*);
Expand Down
71 changes: 71 additions & 0 deletions StreamControl/scimageselect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <QGridLayout>
#include <QDir>

#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<QPushButton*>().isEmpty()) {
qDeleteAll(optionsWidget->findChildren<QPushButton*>());
return;
}

qDeleteAll(optionsWidget->findChildren<QPushButton*>());
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<QPushButton*>());
}

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;
}
37 changes: 37 additions & 0 deletions StreamControl/scimageselect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef SCIMAGESELECT_H
#define SCIMAGESELECT_H

#include <QPushButton>

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