FridgeGrid is a tool intended to help planning cycle exact code for effects on old school hardware. Think of it as a combination of grid paper and fridge magnets in digital form with save and load functions. https://xayax.net/tools/fridgegrid/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MainWindow.cpp 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * src/fridgegrid/MainWindow.cpp
  3. * written by Sven Oliver Moll
  4. *
  5. * distributed under the terms of the GNU General Public License (GPL)
  6. * available at http://www.gnu.org/licenses/gpl.html
  7. */
  8. /* class declaration */
  9. #include "MainWindow.hpp"
  10. /* system headers */
  11. /* Qt headers */
  12. #include <QAction>
  13. #include <QApplication>
  14. #include <QCommonStyle>
  15. #include <QDir>
  16. #include <QFileInfo>
  17. #include <QDockWidget>
  18. #include <QMenu>
  19. #include <QSettings>
  20. #include <QSignalMapper>
  21. #include <QSplitter>
  22. #include <QTextEdit>
  23. #include <QTimer>
  24. #include <QToolBar>
  25. #include <QToolButton>
  26. /* local library headers */
  27. /* local headers */
  28. #include "DragWidget.hpp"
  29. #include <QtDebug>
  30. MainWindow::MainWindow( QWidget *parent, Qt::WindowFlags flags )
  31. : QMainWindow( parent, flags )
  32. , mpSplitter( new QSplitter( Qt::Vertical, this ) )
  33. , mpTextEdit( new QTextEdit( mpSplitter ) )
  34. , mpDragWidget( new DragWidget( mpSplitter ) )
  35. {
  36. QCommonStyle style;
  37. QSettings settings;
  38. QMenu *templateMenu( new QMenu( this ) );
  39. templateMenu->setObjectName( "TemplateMenu" );
  40. mpSplitter->setObjectName( "CentralSplitter" );
  41. mpSplitter->addWidget( mpTextEdit );
  42. mpSplitter->addWidget( mpDragWidget );
  43. mpSplitter->restoreState( settings.value( "Splitter").toByteArray() );
  44. setCentralWidget( mpSplitter );
  45. mpTextEdit->setObjectName( "CommentEditor" );
  46. mpTextEdit->setAcceptRichText( false );
  47. mpTextEdit->setText( settings.value( "Comment" ).toString() );
  48. commentChange();
  49. mpDragWidget->setObjectName( "MainArea" );
  50. mpDragWidget->setTextEdit( mpTextEdit );
  51. mpDragWidget->resize( 400, 50 );
  52. mpDragWidget->setData( settings.value( "Saved" ) );
  53. QToolBar *toolBar = 0;
  54. QAction *action = 0;
  55. toolBar = addToolBar( tr("File") );
  56. toolBar->setObjectName( "FileToolBar" );
  57. toolBar->setContextMenuPolicy( Qt::PreventContextMenu );
  58. action = new QAction( style.standardIcon( QStyle::SP_FileDialogNewFolder ), "New Grid", this );
  59. action->setShortcuts( QKeySequence::New );
  60. action->setMenu( templateMenu );
  61. action->setVisible(true);
  62. toolBar->addAction( action );
  63. // just want to tell the associated button, that we always want the menu list
  64. // can't this be done easier?
  65. {
  66. QList<QWidget*> wl( action->associatedWidgets() );
  67. foreach(QWidget *w, wl)
  68. {
  69. QToolButton *b = qobject_cast<QToolButton*>(w);
  70. if( b )
  71. {
  72. b->setPopupMode( QToolButton::InstantPopup );
  73. }
  74. }
  75. }
  76. QSignalMapper *signalMapper = new QSignalMapper( this );
  77. connect( signalMapper, SIGNAL(mapped(QString)),
  78. mpDragWidget, SLOT(load(QString)) );
  79. QFileInfoList fil( QDir(":/templates/").entryInfoList() );
  80. foreach( const QFileInfo &fi, fil )
  81. {
  82. action = templateMenu->addAction( fi.baseName().replace('_',' ') );
  83. action->setData( fi.filePath() );
  84. connect( action, SIGNAL(triggered()),
  85. signalMapper, SLOT(map()));
  86. signalMapper->setMapping( action, fi.filePath() );
  87. }
  88. action = new QAction( style.standardIcon( QStyle::SP_DialogOpenButton ), "Open File", this );
  89. action->setShortcuts( QKeySequence::Open );
  90. connect( action, SIGNAL(triggered()),
  91. mpDragWidget, SLOT(load()) );
  92. toolBar->addAction( action );
  93. action = new QAction( style.standardIcon( QStyle::SP_DialogSaveButton ), "Save File", this );
  94. action->setShortcuts( QKeySequence::Save );
  95. connect( action, SIGNAL(triggered()),
  96. mpDragWidget, SLOT(save()) );
  97. toolBar->addAction( action );
  98. action = new QAction( style.standardIcon( QStyle::SP_CommandLink ), "Export To PNG", this );
  99. action->setShortcuts( QKeySequence::SaveAs );
  100. connect( action, SIGNAL(triggered()),
  101. mpDragWidget, SLOT(exportPng()) );
  102. toolBar->addAction( action );
  103. toolBar = addToolBar( tr("Element") );
  104. toolBar->setObjectName( "ElementsToolBar" );
  105. toolBar->setContextMenuPolicy( Qt::PreventContextMenu );
  106. action = new QAction( style.standardIcon( QStyle::SP_FileIcon ), "New Element", this );
  107. action->setShortcuts( QKeySequence::AddTab );
  108. connect( action, SIGNAL(triggered()),
  109. mpDragWidget, SLOT(newElement()) );
  110. toolBar->addAction( action );
  111. restoreGeometry( settings.value( "Geometry" ).toByteArray() );
  112. restoreState( settings.value( "State" ).toByteArray() );
  113. QList<QDockWidget*> docks( findChildren<QDockWidget*>() );
  114. foreach( QDockWidget *dock, docks )
  115. {
  116. restoreDockWidget( dock );
  117. }
  118. QTimer *updateDelay = new QTimer( this );
  119. updateDelay->setInterval( 500 );
  120. updateDelay->setSingleShot( true );
  121. connect( mpTextEdit, SIGNAL(textChanged()),
  122. updateDelay, SLOT(start()) );
  123. connect( updateDelay, SIGNAL(timeout()),
  124. this, SLOT(commentChange()) );
  125. }
  126. MainWindow::~MainWindow()
  127. {
  128. QSettings settings;
  129. settings.setValue( "Geometry", saveGeometry() );
  130. settings.setValue( "State", saveState() );
  131. settings.setValue( "Splitter", mpSplitter->saveState() );
  132. settings.setValue( "Comment", mpTextEdit->toPlainText() );
  133. settings.setValue( "Saved", mpDragWidget->getData() );
  134. }
  135. void MainWindow::commentChange()
  136. {
  137. const QStringList &comment( mpTextEdit->toPlainText().split('\n', QString::SkipEmptyParts) );
  138. if( comment.size() > 0 )
  139. {
  140. setWindowTitle( QString( "%1 (%2)").arg( comment.at(0),
  141. QCoreApplication::applicationName() ) );
  142. }
  143. else
  144. {
  145. setWindowTitle( QCoreApplication::applicationName() );
  146. }
  147. }