Browse Source

added open to create new file from template

tags/1.3
Sven Oliver Moll 1 year ago
parent
commit
68143605d2

+ 7
- 0
packaging/debian/changelog View File

@@ -1,3 +1,10 @@
fridgegrid (1.1) unstable; urgency=medium

* export to png
* new file from template

-- Sven Oliver Moll <svolli@svolli.de> Fri, 20 Oct 2017 01:08:49 +0200

fridgegrid (1.0) unstable; urgency=medium

* Initial Release.

+ 16
- 5
src/fridgegrid/DragWidget.cpp View File

@@ -12,6 +12,7 @@
/* system headers */

/* Qt headers */
#include <QAction>
#include <QApplication>
#include <QDomDocument>
#include <QDrag>
@@ -361,13 +362,23 @@ void DragWidget::load()
{
QSettings settings;
QFileInfo lastFilename( settings.value("Filename").toString() );
QString fileName = QFileDialog::getOpenFileName( this, QCoreApplication::applicationName(),
lastFilename.absolutePath(), "*.xml" );
if( fileName.isEmpty() )
QString fileName;
QAction *action = qobject_cast<QAction*>( sender() );
if( action && !action->data().isNull() )
{
return;
fileName = action->data().toString();
settings.remove( "Filename" );
}
else
{
fileName = QFileDialog::getOpenFileName( this, QCoreApplication::applicationName(),
lastFilename.absolutePath(), "*.xml" );
if( fileName.isEmpty() )
{
return;
}
settings.setValue( "Filename", fileName );
}
settings.setValue( "Filename", fileName );

QFile file( fileName );
file.open( QIODevice::ReadOnly );

+ 42
- 5
src/fridgegrid/MainWindow.cpp View File

@@ -15,18 +15,23 @@
#include <QAction>
#include <QApplication>
#include <QCommonStyle>
#include <QDir>
#include <QFileInfo>
#include <QDockWidget>
#include <QMenu>
#include <QSettings>
#include <QSplitter>
#include <QTextEdit>
#include <QTimer>
#include <QToolBar>
#include <QToolButton>

/* local library headers */

/* local headers */
#include "DragWidget.hpp"

#include <QtDebug>

MainWindow::MainWindow( QWidget *parent, Qt::WindowFlags flags )
: QMainWindow( parent, flags )
@@ -36,6 +41,9 @@ MainWindow::MainWindow( QWidget *parent, Qt::WindowFlags flags )
{
QCommonStyle style;
QSettings settings;
QMenu *templateMenu( new QMenu( this ) );

templateMenu->setObjectName( "TemplateMenu" );

mpSplitter->setObjectName( "CentralSplitter" );
mpSplitter->addWidget( mpTextEdit );
@@ -60,19 +68,48 @@ MainWindow::MainWindow( QWidget *parent, Qt::WindowFlags flags )
toolBar->setObjectName( "FileToolBar" );
toolBar->setContextMenuPolicy( Qt::PreventContextMenu );

action = new QAction( style.standardIcon( QStyle::SP_DialogOpenButton ), "Open", this );
action = new QAction( style.standardIcon( QStyle::SP_FileDialogNewFolder ), "New Grid", this );
action->setShortcuts( QKeySequence::New );
action->setMenu( templateMenu );
action->setVisible(true);
toolBar->addAction( action );

// just want to tell the associated button, that we always want the menu list
// can't this be done easier?
{
QList<QWidget*> wl( action->associatedWidgets() );
foreach(QWidget *w, wl)
{
QToolButton *b = qobject_cast<QToolButton*>(w);
if( b )
{
b->setPopupMode( QToolButton::InstantPopup );
}
}
}

QFileInfoList fil( QDir(":/templates/").entryInfoList() );
foreach( const QFileInfo &fi, fil )
{
action = templateMenu->addAction( fi.baseName().replace('_',' ') );
action->setData( fi.filePath() );
connect( action, SIGNAL(triggered()),
mpDragWidget, SLOT(load()) );
}

action = new QAction( style.standardIcon( QStyle::SP_DialogOpenButton ), "Open File", this );
action->setShortcuts( QKeySequence::Open );
connect( action, SIGNAL(triggered()),
mpDragWidget, SLOT(load()) );
toolBar->addAction( action );

action = new QAction( style.standardIcon( QStyle::SP_DialogSaveButton ), "Save", this );
action = new QAction( style.standardIcon( QStyle::SP_DialogSaveButton ), "Save File", this );
action->setShortcuts( QKeySequence::Save );
connect( action, SIGNAL(triggered()),
mpDragWidget, SLOT(save()) );
toolBar->addAction( action );

action = new QAction( style.standardIcon( QStyle::SP_CommandLink ), "Export", this );
action = new QAction( style.standardIcon( QStyle::SP_CommandLink ), "Export To PNG", this );
action->setShortcuts( QKeySequence::SaveAs );
connect( action, SIGNAL(triggered()),
mpDragWidget, SLOT(exportPng()) );
@@ -82,8 +119,8 @@ MainWindow::MainWindow( QWidget *parent, Qt::WindowFlags flags )
toolBar->setObjectName( "ElementsToolBar" );
toolBar->setContextMenuPolicy( Qt::PreventContextMenu );

action = new QAction( style.standardIcon( QStyle::SP_FileIcon ), "New", this );
action->setShortcuts( QKeySequence::New );
action = new QAction( style.standardIcon( QStyle::SP_FileIcon ), "New Element", this );
action->setShortcuts( QKeySequence::AddTab );
connect( action, SIGNAL(triggered()),
mpDragWidget, SLOT(newElement()) );
toolBar->addAction( action );

+ 4
- 0
src/resources/FridgeGrid.qrc View File

@@ -2,5 +2,9 @@
<qresource prefix="/">
<file>fonts/erbosdraco_nova_open_nbp.ttf</file>
<file>fonts/erbosdraco_nova_open_nbp.txt</file>
<file>templates/2600_asym_playfield_template.xml</file>
<file>templates/C64_pal_raster_paper.xml</file>
<file>templates/VIC20_ntsc_raster_paper.xml</file>
<file>templates/VIC20_pal_raster_paper.xml</file>
</qresource>
</RCC>

Loading…
Cancel
Save