Skip to content
Open
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
6 changes: 4 additions & 2 deletions sources/kbe/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#include "platform.h"
#include "mainwindow.h"
#include "guidedialog.h"

#include <QApplication>
#include <QTranslator>
#include <QLocale>
#include <QTextCodec>
#include <QFileInfo>
#include <QDir>
#include <QDebug>
#include <QFile>
#include <QSplashScreen>
#include <QMessageBox>
Expand Down Expand Up @@ -75,8 +75,10 @@ int main(int argc, char *argv[])
QString arg = a.arguments().at(i);
MainWindow::getInstance()->load(arg);
}

QDir dir(QCoreApplication::applicationDirPath( ));
dir.mkdir("templates");
QSettings settings;
settings.setValue("templateStorage", dir.absolutePath()+"/templates/");
// check if startup dialog property exist
if (!settings.contains(Config::settingsShowStartupDialog))
settings.setValue(Config::settingsShowStartupDialog, QVariant(true));
Expand Down
28 changes: 28 additions & 0 deletions sources/plugins/scg/gwf/gwffilewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,31 @@ bool GWFFileWriter::save(QString file_name, QObject *input)
fileOut.close();
return true;
}
bool GWFFileWriter::saveTemp(QString file_name, QList<QGraphicsItem *> items)
{

QFile fileOut(file_name);
if (!fileOut.open(QFile::WriteOnly | QFile::Text)) {
QMessageBox::warning(0, qAppName(),
QObject::tr("File saving error.\nCannot write file %1:\n%2.")
.arg(file_name)
.arg(fileOut.errorString()));
return false;
}
stream.setDevice(&fileOut);
stream.startWriting("UTF-8");
QGraphicsItem * item;
foreach (item, items)
{
if(SCgObject::isSCgObjectType(item->type()) )
{
SCgObject *obj = static_cast<SCgObject*>(item);
stream.writeObject(obj);
}
}

stream.finishWriting();

fileOut.close();
return true;
}
3 changes: 2 additions & 1 deletion sources/plugins/scg/gwf/gwffilewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

#pragma once

#include <QGraphicsItem>
#include "gwfstreamwriter.h"

//! TODO: add error messages
Expand All @@ -26,6 +26,7 @@ class GWFFileWriter
@return If file saved, then return true, else - false.
*/
bool save(QString file_name, QObject *input);
bool saveTemp(QString file_name,QList<QGraphicsItem*> items);

private:

Expand Down
Binary file added sources/plugins/scg/media/icons/template-tool.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions sources/plugins/scg/scg.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
<file>media/icons/tool-select-subgraph.png</file>
<file>media/translations/scg_en_EN.qm</file>
<file>media/translations/scg_ru_RU.qm</file>
<file>media/icons/template-tool.png</file>
</qresource>
</RCC>
38 changes: 37 additions & 1 deletion sources/plugins/scg/scgview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "scgcontentchangedialog.h"
#include "scgwindow.h"
#include "scgtypedialog.h"

#include<QSettings>
#include <math.h>
#include <QUrl>
#include <QContextMenuEvent>
Expand Down Expand Up @@ -45,6 +45,7 @@ SCgView::SCgView(QWidget *parent, SCgWindow *window) :
mActionSelectAll(0),
mContextMenu(0),
mContextObject(0),
mActionSaveTemp(0),
mWindow(window),
isSceneRectControlled(false)
{
Expand Down Expand Up @@ -72,6 +73,10 @@ void SCgView::createActions()
sep->setSeparator(true);
mActionsList.append(sep);

mActionSaveTemp = new QAction(tr("Save as template"), mWindow);
mWindow->addAction(mActionSaveTemp);
connect(mActionSaveTemp, SIGNAL(triggered(bool)), this, SLOT(showSaveTempDialog()));

mActionChangeType = new QAction(tr("Select type"), mWindow);
mActionChangeType->setShortcut(QKeySequence( tr("T") ));
mWindow->addAction(mActionChangeType);
Expand Down Expand Up @@ -145,6 +150,7 @@ void SCgView::createActions()
mActionsList.append(mActionShowAllContent);
mActionsList.append(mActionHideAllContent);
mActionsList.append(mActionDeleteContent);
mActionsList.append(mActionSaveTemp);

sep = new QAction(this);
sep->setSeparator(true);
Expand Down Expand Up @@ -240,6 +246,7 @@ void SCgView::updateActionsState(int idx)
mActionDelete->setEnabled(isAnySelected);
mActionCut->setEnabled(isAnySelected);
mActionCopy->setEnabled(isAnySelected);
mActionSaveTemp->setEnabled(isAnySelected);

//check for showed/hidden contents
items = scene()->items();
Expand Down Expand Up @@ -302,6 +309,7 @@ void SCgView::selectAllCommand() const
(*it)->setSelected(true);
}


void SCgView::keyPressEvent(QKeyEvent *event)
{
QGraphicsView::keyPressEvent(event);
Expand Down Expand Up @@ -402,6 +410,34 @@ void SCgView::swapPairOrient()
static_cast<SCgScene*>(scene())->swapPairOrientCommand(pair);
}

void SCgView::showSaveTempDialog()
{
QDialog dialog(this);
dialog.setWindowTitle(tr("Save template"));
QLineEdit* lineEdit = new QLineEdit(&dialog);
QLabel* label = new QLabel(tr("File name:"),&dialog);

QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel);
buttonBox->setParent(&dialog);

connect(buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));

QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(label);
layout->addWidget(lineEdit);
layout->addWidget(buttonBox);
dialog.setLayout(layout);
QSettings set;
QString fileName ;
if(dialog.exec() == QDialog::Accepted)
{
fileName = set.value("templateStorage").toString() + lineEdit->text() + ".gwf";
mWindow->saveTempToFile(fileName);
}
}

void SCgView::changeIdentifier()
{
Q_ASSERT(mContextObject);
Expand Down
3 changes: 3 additions & 0 deletions sources/plugins/scg/scgview.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Q_OBJECT
* \defgroup menu Actions
* @{
*/
QAction* mActionSaveTemp;
QAction* mActionChangeType;
QAction* mActionChangeContent;
QAction* mActionShowContent;
Expand Down Expand Up @@ -112,6 +113,8 @@ public slots:
void setScene(SCgScene* scene);

private slots:
void showSaveTempDialog();

//! Delete selected sc.g-elements
void deleteSelected();

Expand Down
120 changes: 118 additions & 2 deletions sources/plugins/scg/scgwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
*/

#include "scgwindow.h"

#include <QToolBar>
#include <QTimer>
#include <QDialogButtonBox>
#include <QLabel>
#include <QApplication>
#include <QClipboard>
#include <QAction>
Expand All @@ -21,6 +23,9 @@
#include <QMenu>
#include <QToolButton>
#include <QFileDialog>
#include <QDebug>
#include <QDialog>
#include <QSettings>

#include "scglayoutmanager.h"
#include "arrangers/scgarrangervertical.h"
Expand Down Expand Up @@ -158,10 +163,10 @@ void SCgWindow::createWidgetsForDocks()
}



void SCgWindow::createToolBar()
{
mToolBar = new QToolBar(this);

mToolBar->setIconSize(QSize(32, 32));

QActionGroup* group = new QActionGroup(mToolBar);
Expand All @@ -170,6 +175,7 @@ void SCgWindow::createToolBar()
QAction *action = new QAction(findIcon("tool-select.png"), tr("Selection mode"), mToolBar);
action->setCheckable(true);
action->setChecked(true);
action->setToolTip("<html><body><img src=\"https://i.gifer.com/LRP3.gif\"></body></html>");
action->setShortcut(QKeySequence(tr("1", "Selection mode")));
group->addAction(action);
mToolBar->addAction(action);
Expand Down Expand Up @@ -202,6 +208,14 @@ void SCgWindow::createToolBar()
mToolBar->addAction(action);
mMode2Action[SCgScene::Mode_Contour] = action;
connect(action, SIGNAL(triggered()), this, SLOT(onContourMode()));

//Template tool
action = new QAction(findIcon("template-tool.png"), tr("Create template"), mToolBar);
action->setCheckable(false);
group->addAction(action);
mToolBar->addAction(action);
connect(action, SIGNAL(triggered()), this, SLOT(onTemplateTool()));

//
mToolBar->addSeparator();
//
Expand All @@ -220,6 +234,7 @@ void SCgWindow::createToolBar()
alignButton->addAction(action);
connect(action, SIGNAL(triggered()), this, SLOT(onGridAlignment()));


// tuple alignment
action = new QAction(findIcon("tool-align-tuple.png"), tr("Tuple alignment"), mToolBar);
action->setCheckable(false);
Expand All @@ -241,6 +256,7 @@ void SCgWindow::createToolBar()
alignButton->addAction(action);
connect(action, SIGNAL(triggered()), this, SLOT(onHorizontalAlignment()));


// selection group button
QToolButton *selectButton = new QToolButton(mToolBar);
selectButton->setIcon(findIcon("tool-select-group.png"));
Expand Down Expand Up @@ -327,6 +343,16 @@ bool SCgWindow::loadFromFile(const QString &fileName)
}else
return false;
}
bool SCgWindow::saveTempToFile(const QString &fileName)
{
GWFFileWriter writer;

if (writer.saveTemp(fileName, mView->scene()->selectedItems()))
{
return true;
}else
return false;
}

bool SCgWindow::saveToFile(const QString &fileName)
{
Expand Down Expand Up @@ -385,6 +411,96 @@ void SCgWindow::onGridAlignment()
SCgLayoutManager::instance().arrange(mView, SCgGridArranger::Type);
}

void SCgWindow::onTemplateTool()
{
QSettings set;
QDir dir = QDir(set.value("templateStorage").toString());
QStringList allFiles = dir.entryList(QStringList()<<"*.gwf");
QDialog dialog(this);
dialog.setWindowTitle(tr("Create template"));
QComboBox* list = new QComboBox();

QLabel* label = new QLabel(tr("Choose template"));

QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel);

connect(buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));

QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(label);
layout->addWidget(list);
layout->addWidget(buttonBox);
dialog.setLayout(layout);
list->addItems(allFiles);
if(dialog.exec() == QDialog::Accepted)
{
SCgScene* scene = new SCgScene(new QUndoStack(this), this);
GWFFileLoader loader;
loader.load(set.value("templateStorage").toString()+list->currentText(), scene);
QList<QString> listIdtf;
foreach(QGraphicsItem* item, scene->items())
if(SCgObject::isSCgObjectType(item->type()))
{
if(static_cast <SCgObject*> (item)->typeAlias().split('/').contains("var"))
{
listIdtf<<static_cast <SCgObject*> (item)->idtfValue();
static_cast <SCgObject*> (item)->positionChanged();

}
}
QDialog dialogCreate(this);
dialogCreate.setWindowTitle(tr("Create fragment"));
QDialogButtonBox* bttnBox = new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel);

connect(bttnBox, SIGNAL(accepted()), &dialogCreate, SLOT(accept()));
connect(bttnBox, SIGNAL(rejected()), &dialogCreate, SLOT(reject()));
QVBoxLayout* mainLay = new QVBoxLayout();
QVBoxLayout* fields = new QVBoxLayout();
QList<QLineEdit*> newIdtf;
foreach(QString idtf, listIdtf)
{
QHBoxLayout* row = new QHBoxLayout();
QLabel* var = new QLabel(idtf);
QLineEdit* lineEdit = new QLineEdit();
row->addWidget(var);
row->addWidget(lineEdit);
fields->addLayout(row);
newIdtf<<lineEdit;
}
mainLay->addLayout(fields);
mainLay->addWidget(bttnBox);
dialogCreate.setLayout(mainLay);
if(dialogCreate.exec() == QDialog::Accepted){
for(int i =0;i<newIdtf.size();i++){
foreach(QGraphicsItem* item, scene->items()){
if(SCgObject::isSCgObjectType(item->type())){
if(static_cast<SCgObject*>(item)->idtfValue() == listIdtf[i]){
scene->changeIdtfCommand(static_cast<SCgObject*>(item), newIdtf[i]->text());
QList<QString> type = static_cast<SCgObject*>(item)->typeAlias().split('/');
type.replace(type.indexOf("var"), "const");
QString newType="";
foreach(QString t, type)
newType += t + "/";
newType.chop(1);
static_cast<SCgObject*>(item)->setTypeAlias(newType);
}
}

}
}
foreach(QGraphicsItem* item, scene->items()){
if(SCgObject::isSCgObjectType(item->type())){
item->setSelected(true);
mView->scene()->addItem(item);
}
}
}
}
}

void SCgWindow::onTupleAlignment()
{
SCgLayoutManager::instance().arrange(mView, SCgTupleArranger::Type);
Expand Down
Loading