2012-11-22 12:30:02 +00:00
# include "view.hpp"
2012-11-22 14:09:04 +00:00
# include <sstream>
2012-11-26 11:29:22 +00:00
# include <stdexcept>
2012-11-22 13:10:23 +00:00
# include <QCloseEvent>
2012-11-22 13:49:58 +00:00
# include <QMenuBar>
2018-12-21 12:17:09 +00:00
# include <QMessageBox>
2015-06-12 13:10:12 +00:00
# include <QApplication>
2014-09-17 07:13:21 +00:00
# include <QDesktopWidget>
2015-05-17 10:45:13 +00:00
# include <QScrollArea>
# include <QScrollBar>
2019-12-20 09:36:32 +00:00
# include <QScreen>
2012-11-22 14:54:31 +00:00
# include "../../model/doc/document.hpp"
2022-08-19 17:19:42 +00:00
# include "../../model/doc/state.hpp"
2015-12-12 13:49:16 +00:00
# include "../../model/prefs/state.hpp"
2016-07-24 01:23:02 +00:00
# include "../../model/prefs/shortcut.hpp"
2014-05-10 10:04:36 +00:00
2014-09-04 15:45:43 +00:00
# include "../../model/world/idtable.hpp"
2012-12-11 12:22:43 +00:00
# include "../world/subviews.hpp"
2019-07-01 23:26:05 +00:00
# include "../world/scenesubview.hpp"
2015-05-17 10:45:13 +00:00
# include "../world/tablesubview.hpp"
2022-04-27 01:31:27 +00:00
# include "../world/dialoguesubview.hpp"
# include "../world/scriptsubview.hpp"
2014-05-10 10:04:36 +00:00
2012-12-11 14:35:47 +00:00
# include "../tools/subviews.hpp"
2014-05-10 10:04:36 +00:00
2020-04-18 20:54:21 +00:00
# include <components/misc/helpviewer.hpp>
2018-12-21 12:17:09 +00:00
# include <components/version/version.hpp>
2012-11-22 13:10:23 +00:00
# include "viewmanager.hpp"
2012-11-23 11:20:35 +00:00
# include "operations.hpp"
2012-12-11 12:22:43 +00:00
# include "subview.hpp"
2014-09-04 15:45:43 +00:00
# include "globaldebugprofilemenu.hpp"
2014-09-05 11:49:34 +00:00
# include "runlogsubview.hpp"
# include "subviewfactoryimp.hpp"
2012-11-22 13:10:23 +00:00
void CSVDoc : : View : : closeEvent ( QCloseEvent * event )
{
if ( ! mViewManager . closeRequest ( this ) )
event - > ignore ( ) ;
2014-09-09 03:04:48 +00:00
else
{
// closeRequest() returns true if last document
2014-09-09 11:09:37 +00:00
mViewManager . removeDocAndView ( mDocument ) ;
2014-09-09 03:04:48 +00:00
}
2012-11-22 13:10:23 +00:00
}
2012-11-22 23:36:01 +00:00
void CSVDoc : : View : : setupFileMenu ( )
{
2016-07-29 19:00:35 +00:00
QMenu * file = menuBar ( ) - > addMenu ( tr ( " File " ) ) ;
2012-11-22 23:36:01 +00:00
2018-09-13 18:15:59 +00:00
QAction * newGame = createMenuEntry ( " New Game " , " :./menu-new-game.png " , file , " document-file-newgame " ) ;
2022-08-23 02:28:58 +00:00
connect ( newGame , & QAction : : triggered , this , & View : : newGameRequest ) ;
2013-09-08 10:06:28 +00:00
2018-09-13 18:15:59 +00:00
QAction * newAddon = createMenuEntry ( " New Addon " , " :./menu-new-addon.png " , file , " document-file-newaddon " ) ;
2022-08-23 02:28:58 +00:00
connect ( newAddon , & QAction : : triggered , this , & View : : newAddonRequest ) ;
2012-11-23 13:05:49 +00:00
2018-09-13 18:15:59 +00:00
QAction * open = createMenuEntry ( " Open " , " :./menu-open.png " , file , " document-file-open " ) ;
2022-08-23 02:28:58 +00:00
connect ( open , & QAction : : triggered , this , & View : : loadDocumentRequest ) ;
2013-02-02 15:14:58 +00:00
2018-09-13 18:15:59 +00:00
QAction * save = createMenuEntry ( " Save " , " :./menu-save.png " , file , " document-file-save " ) ;
2022-08-23 02:28:58 +00:00
connect ( save , & QAction : : triggered , this , & View : : save ) ;
2018-07-27 19:45:25 +00:00
mSave = save ;
2022-08-23 02:28:58 +00:00
2021-10-03 19:13:51 +00:00
file - > addSeparator ( ) ;
2013-03-02 18:49:26 +00:00
2018-09-13 18:15:59 +00:00
QAction * verify = createMenuEntry ( " Verify " , " :./menu-verify.png " , file , " document-file-verify " ) ;
2022-08-23 02:28:58 +00:00
connect ( verify , & QAction : : triggered , this , & View : : verify ) ;
2018-07-27 19:45:25 +00:00
mVerify = verify ;
2013-04-02 13:47:25 +00:00
2018-09-13 18:15:59 +00:00
QAction * merge = createMenuEntry ( " Merge " , " :./menu-merge.png " , file , " document-file-merge " ) ;
2022-08-23 02:28:58 +00:00
connect ( merge , & QAction : : triggered , this , & View : : merge ) ;
2018-07-27 19:45:25 +00:00
mMerge = merge ;
2015-08-06 10:52:10 +00:00
2018-09-13 18:15:59 +00:00
QAction * loadErrors = createMenuEntry ( " Error Log " , " :./error-log.png " , file , " document-file-errorlog " ) ;
2022-08-23 02:28:58 +00:00
connect ( loadErrors , & QAction : : triggered , this , & View : : loadErrorLog ) ;
2014-05-10 10:04:36 +00:00
2018-07-27 19:45:25 +00:00
QAction * meta = createMenuEntry ( CSMWorld : : UniversalId : : Type_MetaDatas , file , " document-file-metadata " ) ;
2022-08-23 02:28:58 +00:00
connect ( meta , & QAction : : triggered , this , & View : : addMetaDataSubView ) ;
2015-06-26 14:11:00 +00:00
2021-10-03 19:13:51 +00:00
file - > addSeparator ( ) ;
2022-08-23 02:28:58 +00:00
2018-09-13 18:15:59 +00:00
QAction * close = createMenuEntry ( " Close " , " :./menu-close.png " , file , " document-file-close " ) ;
2022-08-23 02:28:58 +00:00
connect ( close , & QAction : : triggered , this , & View : : close ) ;
2013-03-03 21:58:26 +00:00
2018-09-13 18:15:59 +00:00
QAction * exit = createMenuEntry ( " Exit " , " :./menu-exit.png " , file , " document-file-exit " ) ;
2022-08-23 02:28:58 +00:00
connect ( exit , & QAction : : triggered , this , & View : : exit ) ;
2013-03-03 21:58:26 +00:00
2022-08-23 02:28:58 +00:00
connect ( this , & View : : exitApplicationRequest , & mViewManager , & ViewManager : : exitApplication ) ;
2012-11-22 23:36:01 +00:00
}
2018-07-05 15:29:58 +00:00
namespace
2018-07-04 19:47:16 +00:00
{
2018-07-05 15:29:58 +00:00
void updateUndoRedoAction ( QAction * action , const std : : string & settingsKey )
{
QKeySequence seq ;
CSMPrefs : : State : : get ( ) . getShortcutManager ( ) . getSequence ( settingsKey , seq ) ;
action - > setShortcut ( seq ) ;
}
2018-07-04 19:47:16 +00:00
}
void CSVDoc : : View : : undoActionChanged ( )
{
updateUndoRedoAction ( mUndo , " document-edit-undo " ) ;
}
void CSVDoc : : View : : redoActionChanged ( )
{
updateUndoRedoAction ( mRedo , " document-edit-redo " ) ;
}
2012-11-22 14:54:31 +00:00
void CSVDoc : : View : : setupEditMenu ( )
{
2016-07-29 19:00:35 +00:00
QMenu * edit = menuBar ( ) - > addMenu ( tr ( " Edit " ) ) ;
2012-11-22 14:54:31 +00:00
2016-07-29 19:00:35 +00:00
mUndo = mDocument - > getUndoStack ( ) . createUndoAction ( this , tr ( " Undo " ) ) ;
2016-07-27 04:24:16 +00:00
setupShortcut ( " document-edit-undo " , mUndo ) ;
2022-08-23 02:28:58 +00:00
connect ( mUndo , & QAction : : changed , this , & View : : undoActionChanged ) ;
2018-09-13 18:15:59 +00:00
mUndo - > setIcon ( QIcon ( QString : : fromStdString ( " :./menu-undo.png " ) ) ) ;
2012-11-22 23:51:04 +00:00
edit - > addAction ( mUndo ) ;
2012-11-22 14:54:31 +00:00
2018-07-04 19:47:16 +00:00
mRedo = mDocument - > getUndoStack ( ) . createRedoAction ( this , tr ( " Redo " ) ) ;
2022-08-23 02:28:58 +00:00
connect ( mRedo , & QAction : : changed , this , & View : : redoActionChanged ) ;
2016-07-27 04:24:16 +00:00
setupShortcut ( " document-edit-redo " , mRedo ) ;
2018-09-13 18:15:59 +00:00
mRedo - > setIcon ( QIcon ( QString : : fromStdString ( " :./menu-redo.png " ) ) ) ;
2012-11-22 23:51:04 +00:00
edit - > addAction ( mRedo ) ;
2013-05-11 12:40:10 +00:00
2018-09-13 18:15:59 +00:00
QAction * userSettings = createMenuEntry ( " Preferences " , " :./menu-preferences.png " , edit , " document-edit-preferences " ) ;
2022-08-23 02:28:58 +00:00
connect ( userSettings , & QAction : : triggered , this , & View : : editSettingsRequest ) ;
2015-03-19 20:03:24 +00:00
2018-07-27 19:45:25 +00:00
QAction * search = createMenuEntry ( CSMWorld : : UniversalId : : Type_Search , edit , " document-edit-search " ) ;
2022-08-23 02:28:58 +00:00
connect ( search , & QAction : : triggered , this , & View : : addSearchSubView ) ;
2012-11-22 14:54:31 +00:00
}
void CSVDoc : : View : : setupViewMenu ( )
2012-11-22 13:49:58 +00:00
{
2016-07-29 19:00:35 +00:00
QMenu * view = menuBar ( ) - > addMenu ( tr ( " View " ) ) ;
2012-11-22 13:49:58 +00:00
2018-09-13 18:15:59 +00:00
QAction * newWindow = createMenuEntry ( " New View " , " :./menu-new-window.png " , view , " document-view-newview " ) ;
2022-08-23 02:28:58 +00:00
connect ( newWindow , & QAction : : triggered , this , & View : : newView ) ;
2013-07-22 19:18:47 +00:00
2018-09-13 18:15:59 +00:00
mShowStatusBar = createMenuEntry ( " Toggle Status Bar " , " :./menu-status-bar.png " , view , " document-view-statusbar " ) ;
2022-08-23 02:28:58 +00:00
connect ( mShowStatusBar , & QAction : : toggled , this , & View : : toggleShowStatusBar ) ;
2018-07-27 19:45:25 +00:00
mShowStatusBar - > setCheckable ( true ) ;
2015-12-12 13:49:16 +00:00
mShowStatusBar - > setChecked ( CSMPrefs : : get ( ) [ " Windows " ] [ " show-statusbar " ] . isTrue ( ) ) ;
2013-07-25 12:29:56 +00:00
view - > addAction ( mShowStatusBar ) ;
2013-07-30 13:55:50 +00:00
2018-07-27 19:45:25 +00:00
QAction * filters = createMenuEntry ( CSMWorld : : UniversalId : : Type_Filters , view , " document-mechanics-filters " ) ;
2022-08-23 02:28:58 +00:00
connect ( filters , & QAction : : triggered , this , & View : : addFiltersSubView ) ;
2012-11-22 13:49:58 +00:00
}
2012-11-23 12:15:45 +00:00
void CSVDoc : : View : : setupWorldMenu ( )
{
2016-07-29 19:00:35 +00:00
QMenu * world = menuBar ( ) - > addMenu ( tr ( " World " ) ) ;
2012-11-23 12:15:45 +00:00
2018-07-27 19:45:25 +00:00
QAction * referenceables = createMenuEntry ( CSMWorld : : UniversalId : : Type_Referenceables , world , " document-world-referencables " ) ;
2022-08-23 02:28:58 +00:00
connect ( referenceables , & QAction : : triggered , this , & View : : addReferenceablesSubView ) ;
2013-07-20 11:46:56 +00:00
2018-07-27 19:45:25 +00:00
QAction * references = createMenuEntry ( CSMWorld : : UniversalId : : Type_References , world , " document-world-references " ) ;
2022-08-23 02:28:58 +00:00
connect ( references , & QAction : : triggered , this , & View : : addReferencesSubView ) ;
2021-10-03 19:13:51 +00:00
world - > addSeparator ( ) ;
QAction * cells = createMenuEntry ( CSMWorld : : UniversalId : : Type_Cells , world , " document-world-cells " ) ;
2022-08-23 02:28:58 +00:00
connect ( cells , & QAction : : triggered , this , & View : : addCellsSubView ) ;
2013-07-20 11:46:56 +00:00
2018-07-27 19:45:25 +00:00
QAction * lands = createMenuEntry ( CSMWorld : : UniversalId : : Type_Lands , world , " document-world-lands " ) ;
2022-08-23 02:28:58 +00:00
connect ( lands , & QAction : : triggered , this , & View : : addLandsSubView ) ;
2017-08-24 21:12:15 +00:00
2018-07-27 19:45:25 +00:00
QAction * landTextures = createMenuEntry ( CSMWorld : : UniversalId : : Type_LandTextures , world , " document-world-landtextures " ) ;
2022-08-23 02:28:58 +00:00
connect ( landTextures , & QAction : : triggered , this , & View : : addLandTexturesSubView ) ;
2017-08-24 21:12:15 +00:00
2018-07-27 19:45:25 +00:00
QAction * grid = createMenuEntry ( CSMWorld : : UniversalId : : Type_Pathgrids , world , " document-world-pathgrid " ) ;
2022-08-23 02:28:58 +00:00
connect ( grid , & QAction : : triggered , this , & View : : addPathgridSubView ) ;
2014-10-02 13:16:19 +00:00
2021-10-03 19:13:51 +00:00
world - > addSeparator ( ) ;
QAction * regions = createMenuEntry ( CSMWorld : : UniversalId : : Type_Regions , world , " document-world-regions " ) ;
2022-08-23 02:28:58 +00:00
connect ( regions , & QAction : : triggered , this , & View : : addRegionsSubView ) ;
2013-07-20 11:46:56 +00:00
2018-07-27 19:45:25 +00:00
QAction * regionMap = createMenuEntry ( CSMWorld : : UniversalId : : Type_RegionMap , world , " document-world-regionmap " ) ;
2022-08-23 02:28:58 +00:00
connect ( regionMap , & QAction : : triggered , this , & View : : addRegionMapSubView ) ;
2013-07-20 11:46:56 +00:00
}
void CSVDoc : : View : : setupMechanicsMenu ( )
{
2016-07-29 19:00:35 +00:00
QMenu * mechanics = menuBar ( ) - > addMenu ( tr ( " Mechanics " ) ) ;
2013-07-20 11:46:56 +00:00
2021-10-03 19:13:51 +00:00
QAction * scripts = createMenuEntry ( CSMWorld : : UniversalId : : Type_Scripts , mechanics , " document-mechanics-scripts " ) ;
2022-08-23 02:28:58 +00:00
connect ( scripts , & QAction : : triggered , this , & View : : addScriptsSubView ) ;
2021-10-03 19:13:51 +00:00
QAction * startScripts = createMenuEntry ( CSMWorld : : UniversalId : : Type_StartScripts , mechanics , " document-mechanics-startscripts " ) ;
2022-08-23 02:28:58 +00:00
connect ( startScripts , & QAction : : triggered , this , & View : : addStartScriptsSubView ) ;
2021-10-03 19:13:51 +00:00
2018-07-27 19:45:25 +00:00
QAction * globals = createMenuEntry ( CSMWorld : : UniversalId : : Type_Globals , mechanics , " document-mechanics-globals " ) ;
2022-08-23 02:28:58 +00:00
connect ( globals , & QAction : : triggered , this , & View : : addGlobalsSubView ) ;
2012-11-26 11:29:22 +00:00
2018-07-27 19:45:25 +00:00
QAction * gmsts = createMenuEntry ( CSMWorld : : UniversalId : : Type_Gmsts , mechanics , " document-mechanics-gamesettings " ) ;
2022-08-23 02:28:58 +00:00
connect ( gmsts , & QAction : : triggered , this , & View : : addGmstsSubView ) ;
2021-10-03 19:13:51 +00:00
mechanics - > addSeparator ( ) ;
2013-10-21 16:04:40 +00:00
2018-07-27 19:45:25 +00:00
QAction * spells = createMenuEntry ( CSMWorld : : UniversalId : : Type_Spells , mechanics , " document-mechanics-spells " ) ;
2022-08-23 02:28:58 +00:00
connect ( spells , & QAction : : triggered , this , & View : : addSpellsSubView ) ;
2014-06-30 18:40:34 +00:00
2018-07-27 19:45:25 +00:00
QAction * enchantments = createMenuEntry ( CSMWorld : : UniversalId : : Type_Enchantments , mechanics , " document-mechanics-enchantments " ) ;
2022-08-23 02:28:58 +00:00
connect ( enchantments , & QAction : : triggered , this , & View : : addEnchantmentsSubView ) ;
2014-09-26 11:12:17 +00:00
2018-07-27 19:45:25 +00:00
QAction * magicEffects = createMenuEntry ( CSMWorld : : UniversalId : : Type_MagicEffects , mechanics , " document-mechanics-magiceffects " ) ;
2022-08-23 02:28:58 +00:00
connect ( magicEffects , & QAction : : triggered , this , & View : : addMagicEffectsSubView ) ;
2013-10-21 16:04:40 +00:00
}
void CSVDoc : : View : : setupCharacterMenu ( )
{
QMenu * characters = menuBar ( ) - > addMenu ( tr ( " Characters " ) ) ;
2018-07-27 19:45:25 +00:00
QAction * skills = createMenuEntry ( CSMWorld : : UniversalId : : Type_Skills , characters , " document-character-skills " ) ;
2022-08-23 02:28:58 +00:00
connect ( skills , & QAction : : triggered , this , & View : : addSkillsSubView ) ;
2013-03-21 13:31:32 +00:00
2018-07-27 19:45:25 +00:00
QAction * classes = createMenuEntry ( CSMWorld : : UniversalId : : Type_Classes , characters , " document-character-classes " ) ;
2022-08-23 02:28:58 +00:00
connect ( classes , & QAction : : triggered , this , & View : : addClassesSubView ) ;
2013-03-25 12:22:06 +00:00
2018-07-27 19:45:25 +00:00
QAction * factions = createMenuEntry ( CSMWorld : : UniversalId : : Type_Faction , characters , " document-character-factions " ) ;
2022-08-23 02:28:58 +00:00
connect ( factions , & QAction : : triggered , this , & View : : addFactionsSubView ) ;
2013-04-04 12:34:39 +00:00
2018-07-27 19:45:25 +00:00
QAction * races = createMenuEntry ( CSMWorld : : UniversalId : : Type_Races , characters , " document-character-races " ) ;
2022-08-23 02:28:58 +00:00
connect ( races , & QAction : : triggered , this , & View : : addRacesSubView ) ;
2013-04-07 18:26:39 +00:00
2018-07-27 19:45:25 +00:00
QAction * birthsigns = createMenuEntry ( CSMWorld : : UniversalId : : Type_Birthsigns , characters , " document-character-birthsigns " ) ;
2022-08-23 02:28:58 +00:00
connect ( birthsigns , & QAction : : triggered , this , & View : : addBirthsignsSubView ) ;
2021-10-03 19:13:51 +00:00
QAction * bodyParts = createMenuEntry ( CSMWorld : : UniversalId : : Type_BodyParts , characters , " document-character-bodyparts " ) ;
2022-08-23 02:28:58 +00:00
connect ( bodyParts , & QAction : : triggered , this , & View : : addBodyPartsSubView ) ;
2013-10-20 15:13:31 +00:00
2021-10-03 19:13:51 +00:00
characters - > addSeparator ( ) ;
2022-08-23 02:28:58 +00:00
2018-07-27 19:45:25 +00:00
QAction * topics = createMenuEntry ( CSMWorld : : UniversalId : : Type_Topics , characters , " document-character-topics " ) ;
2022-08-23 02:28:58 +00:00
connect ( topics , & QAction : : triggered , this , & View : : addTopicsSubView ) ;
2013-10-20 15:13:31 +00:00
2018-07-27 19:45:25 +00:00
QAction * topicInfos = createMenuEntry ( CSMWorld : : UniversalId : : Type_TopicInfos , characters , " document-character-topicinfos " ) ;
2022-08-23 02:28:58 +00:00
connect ( topicInfos , & QAction : : triggered , this , & View : : addTopicInfosSubView ) ;
2021-10-03 19:13:51 +00:00
characters - > addSeparator ( ) ;
2022-08-23 02:28:58 +00:00
2021-10-03 19:13:51 +00:00
QAction * journals = createMenuEntry ( CSMWorld : : UniversalId : : Type_Journals , characters , " document-character-journals " ) ;
2022-08-23 02:28:58 +00:00
connect ( journals , & QAction : : triggered , this , & View : : addJournalsSubView ) ;
2013-10-29 12:18:22 +00:00
2018-07-27 19:45:25 +00:00
QAction * journalInfos = createMenuEntry ( CSMWorld : : UniversalId : : Type_JournalInfos , characters , " document-character-journalinfos " ) ;
2022-08-23 02:28:58 +00:00
connect ( journalInfos , & QAction : : triggered , this , & View : : addJournalInfosSubView ) ;
2013-07-20 11:46:56 +00:00
}
2013-05-11 15:01:16 +00:00
2013-07-20 11:46:56 +00:00
void CSVDoc : : View : : setupAssetsMenu ( )
{
2016-07-29 19:00:35 +00:00
QMenu * assets = menuBar ( ) - > addMenu ( tr ( " Assets " ) ) ;
2013-07-08 11:12:50 +00:00
2018-09-13 18:15:59 +00:00
QAction * reload = createMenuEntry ( " Reload " , " :./menu-reload.png " , assets , " document-assets-reload " ) ;
2022-08-23 02:53:19 +00:00
connect ( reload , & QAction : : triggered , & mDocument - > getData ( ) , & CSMWorld : : Data : : assetsChanged ) ;
2017-08-19 07:43:31 +00:00
assets - > addSeparator ( ) ;
2018-07-27 19:45:25 +00:00
QAction * sounds = createMenuEntry ( CSMWorld : : UniversalId : : Type_Sounds , assets , " document-assets-sounds " ) ;
2022-08-23 02:28:58 +00:00
connect ( sounds , & QAction : : triggered , this , & View : : addSoundsSubView ) ;
2014-07-05 13:51:17 +00:00
2018-07-27 19:45:25 +00:00
QAction * soundGens = createMenuEntry ( CSMWorld : : UniversalId : : Type_SoundGens , assets , " document-assets-soundgens " ) ;
2022-08-23 02:28:58 +00:00
connect ( soundGens , & QAction : : triggered , this , & View : : addSoundGensSubView ) ;
2014-09-23 11:21:54 +00:00
2014-07-05 13:51:17 +00:00
assets - > addSeparator ( ) ; // resources follow here
2018-07-27 19:45:25 +00:00
QAction * meshes = createMenuEntry ( CSMWorld : : UniversalId : : Type_Meshes , assets , " document-assets-meshes " ) ;
2022-08-23 02:28:58 +00:00
connect ( meshes , & QAction : : triggered , this , & View : : addMeshesSubView ) ;
2014-07-05 13:51:17 +00:00
2018-07-27 19:45:25 +00:00
QAction * icons = createMenuEntry ( CSMWorld : : UniversalId : : Type_Icons , assets , " document-assets-icons " ) ;
2022-08-23 02:28:58 +00:00
connect ( icons , & QAction : : triggered , this , & View : : addIconsSubView ) ;
2014-07-05 13:51:17 +00:00
2018-07-27 19:45:25 +00:00
QAction * musics = createMenuEntry ( CSMWorld : : UniversalId : : Type_Musics , assets , " document-assets-musics " ) ;
2022-08-23 02:28:58 +00:00
connect ( musics , & QAction : : triggered , this , & View : : addMusicsSubView ) ;
2014-07-05 13:51:17 +00:00
2018-07-27 19:45:25 +00:00
QAction * soundFiles = createMenuEntry ( CSMWorld : : UniversalId : : Type_SoundsRes , assets , " document-assets-soundres " ) ;
2022-08-23 02:28:58 +00:00
connect ( soundFiles , & QAction : : triggered , this , & View : : addSoundsResSubView ) ;
2014-07-05 13:51:17 +00:00
2018-07-27 19:45:25 +00:00
QAction * textures = createMenuEntry ( CSMWorld : : UniversalId : : Type_Textures , assets , " document-assets-textures " ) ;
2022-08-23 02:28:58 +00:00
connect ( textures , & QAction : : triggered , this , & View : : addTexturesSubView ) ;
2014-07-05 13:51:17 +00:00
2018-07-27 19:45:25 +00:00
QAction * videos = createMenuEntry ( CSMWorld : : UniversalId : : Type_Videos , assets , " document-assets-videos " ) ;
2022-08-23 02:28:58 +00:00
connect ( videos , & QAction : : triggered , this , & View : : addVideosSubView ) ;
2012-11-23 12:15:45 +00:00
}
2014-08-04 11:36:01 +00:00
void CSVDoc : : View : : setupDebugMenu ( )
{
QMenu * debug = menuBar ( ) - > addMenu ( tr ( " Debug " ) ) ;
2018-07-27 19:45:25 +00:00
QAction * profiles = createMenuEntry ( CSMWorld : : UniversalId : : Type_DebugProfiles , debug , " document-debug-profiles " ) ;
2022-08-23 02:28:58 +00:00
connect ( profiles , & QAction : : triggered , this , & View : : addDebugProfilesSubView ) ;
2014-09-02 08:21:17 +00:00
debug - > addSeparator ( ) ;
2014-09-04 15:45:43 +00:00
mGlobalDebugProfileMenu = new GlobalDebugProfileMenu (
& dynamic_cast < CSMWorld : : IdTable & > ( * mDocument - > getData ( ) . getTableModel (
CSMWorld : : UniversalId : : Type_DebugProfiles ) ) , this ) ;
2022-08-23 02:28:58 +00:00
connect ( mGlobalDebugProfileMenu , & GlobalDebugProfileMenu : : triggered ,
this , [ this ] ( const std : : string & profile ) { this - > run ( profile , " " ) ; } ) ;
2014-09-04 15:45:43 +00:00
QAction * runDebug = debug - > addMenu ( mGlobalDebugProfileMenu ) ;
runDebug - > setText ( tr ( " Run OpenMW " ) ) ;
2016-07-27 04:24:16 +00:00
setupShortcut ( " document-debug-run " , runDebug ) ;
2018-09-13 18:15:59 +00:00
runDebug - > setIcon ( QIcon ( QString : : fromStdString ( " :./run-openmw.png " ) ) ) ;
2016-07-27 04:24:16 +00:00
2018-09-13 18:15:59 +00:00
QAction * stopDebug = createMenuEntry ( " Stop OpenMW " , " :./stop-openmw.png " , debug , " document-debug-shutdown " ) ;
2022-08-23 02:28:58 +00:00
connect ( stopDebug , & QAction : : triggered , this , & View : : stop ) ;
2018-07-27 19:45:25 +00:00
mStopDebug = stopDebug ;
2014-09-05 11:49:34 +00:00
2018-07-27 19:45:25 +00:00
QAction * runLog = createMenuEntry ( CSMWorld : : UniversalId : : Type_RunLog , debug , " document-debug-runlog " ) ;
2022-08-23 02:28:58 +00:00
connect ( runLog , & QAction : : triggered , this , & View : : addRunLogSubView ) ;
2018-07-27 19:45:25 +00:00
}
2018-12-21 12:17:09 +00:00
void CSVDoc : : View : : setupHelpMenu ( )
{
QMenu * help = menuBar ( ) - > addMenu ( tr ( " Help " ) ) ;
2020-04-18 20:54:21 +00:00
QAction * helpInfo = createMenuEntry ( " Help " , " :/info.png " , help , " document-help-help " ) ;
2022-08-23 02:28:58 +00:00
connect ( helpInfo , & QAction : : triggered , this , & View : : openHelp ) ;
2020-04-18 20:54:21 +00:00
QAction * tutorial = createMenuEntry ( " Tutorial " , " :/info.png " , help , " document-help-tutorial " ) ;
2022-08-23 02:28:58 +00:00
connect ( tutorial , & QAction : : triggered , this , & View : : tutorial ) ;
2020-04-18 20:54:21 +00:00
2018-12-21 12:17:09 +00:00
QAction * about = createMenuEntry ( " About OpenMW-CS " , " :./info.png " , help , " document-help-about " ) ;
2022-08-23 02:28:58 +00:00
connect ( about , & QAction : : triggered , this , & View : : infoAbout ) ;
2018-12-21 12:17:09 +00:00
QAction * aboutQt = createMenuEntry ( " About Qt " , " :./qt.png " , help , " document-help-qt " ) ;
2022-08-23 02:28:58 +00:00
connect ( aboutQt , & QAction : : triggered , this , & View : : infoAboutQt ) ;
2018-12-21 12:17:09 +00:00
}
2018-07-27 19:45:25 +00:00
QAction * CSVDoc : : View : : createMenuEntry ( CSMWorld : : UniversalId : : Type type , QMenu * menu , const char * shortcutName )
{
const std : : string title = CSMWorld : : UniversalId ( type ) . getTypeName ( ) ;
QAction * entry = new QAction ( QString : : fromStdString ( title ) , this ) ;
setupShortcut ( shortcutName , entry ) ;
const std : : string iconName = CSMWorld : : UniversalId ( type ) . getIcon ( ) ;
if ( ! iconName . empty ( ) & & iconName ! = " :placeholder " )
entry - > setIcon ( QIcon ( QString : : fromStdString ( iconName ) ) ) ;
menu - > addAction ( entry ) ;
return entry ;
2014-08-04 11:36:01 +00:00
}
2018-09-13 18:15:59 +00:00
QAction * CSVDoc : : View : : createMenuEntry ( const std : : string & title , const std : : string & iconName , QMenu * menu , const char * shortcutName )
{
QAction * entry = new QAction ( QString : : fromStdString ( title ) , this ) ;
setupShortcut ( shortcutName , entry ) ;
if ( ! iconName . empty ( ) & & iconName ! = " :placeholder " )
entry - > setIcon ( QIcon ( QString : : fromStdString ( iconName ) ) ) ;
menu - > addAction ( entry ) ;
return entry ;
}
2012-11-22 14:54:31 +00:00
void CSVDoc : : View : : setupUi ( )
{
2012-11-22 23:36:01 +00:00
setupFileMenu ( ) ;
2012-11-22 14:54:31 +00:00
setupEditMenu ( ) ;
setupViewMenu ( ) ;
2012-11-23 12:15:45 +00:00
setupWorldMenu ( ) ;
2013-07-20 11:46:56 +00:00
setupMechanicsMenu ( ) ;
2013-10-21 16:04:40 +00:00
setupCharacterMenu ( ) ;
2013-07-20 11:46:56 +00:00
setupAssetsMenu ( ) ;
2014-08-04 11:36:01 +00:00
setupDebugMenu ( ) ;
2018-12-21 12:17:09 +00:00
setupHelpMenu ( ) ;
2012-11-22 14:54:31 +00:00
}
2016-07-27 04:24:16 +00:00
void CSVDoc : : View : : setupShortcut ( const char * name , QAction * action )
{
CSMPrefs : : Shortcut * shortcut = new CSMPrefs : : Shortcut ( name , this ) ;
shortcut - > associateAction ( action ) ;
}
2014-10-27 07:57:18 +00:00
void CSVDoc : : View : : updateTitle ( )
2012-11-22 14:09:04 +00:00
{
std : : ostringstream stream ;
2022-06-19 11:28:33 +00:00
stream < < mDocument - > getSavePath ( ) . filename ( ) . string ( ) ; //TODO(Project579): let's hope unicode characters are never used in these filenames on windows or this will break
2012-11-22 14:09:04 +00:00
2012-12-08 13:44:03 +00:00
if ( mDocument - > getState ( ) & CSMDoc : : State_Modified )
2012-11-22 22:42:17 +00:00
stream < < " * " ;
2012-11-22 14:09:04 +00:00
if ( mViewTotal > 1 )
stream < < " [ " < < ( mViewIndex + 1 ) < < " / " < < mViewTotal < < " ] " ;
2015-12-12 13:49:16 +00:00
CSMPrefs : : Category & windows = CSMPrefs : : State : : get ( ) [ " Windows " ] ;
2014-10-27 07:57:18 +00:00
2015-12-12 13:49:16 +00:00
bool hideTitle = windows [ " hide-subview " ] . isTrue ( ) & &
2014-10-27 07:57:18 +00:00
mSubViews . size ( ) = = 1 & & ! mSubViews . at ( 0 ) - > isFloating ( ) ;
if ( hideTitle )
stream < < " - " < < mSubViews . at ( 0 ) - > getTitle ( ) ;
2014-09-23 07:01:08 +00:00
2015-03-16 14:45:41 +00:00
setWindowTitle ( QString : : fromUtf8 ( stream . str ( ) . c_str ( ) ) ) ;
2012-11-22 14:09:04 +00:00
}
2016-02-01 11:12:14 +00:00
void CSVDoc : : View : : updateSubViewIndices ( SubView * view )
2014-09-23 07:01:08 +00:00
{
2015-12-12 13:49:16 +00:00
CSMPrefs : : Category & windows = CSMPrefs : : State : : get ( ) [ " Windows " ] ;
2014-09-23 07:01:08 +00:00
if ( view & & mSubViews . contains ( view ) )
2015-05-17 10:45:13 +00:00
{
2014-09-23 07:01:08 +00:00
mSubViews . removeOne ( view ) ;
2015-05-17 10:45:13 +00:00
// adjust (reduce) the scroll area (even floating), except when it is "Scrollbar Only"
2015-12-12 13:49:16 +00:00
if ( windows [ " mainwindow-scrollbar " ] . toString ( ) = = " Grow then Scroll " )
2015-05-17 10:45:13 +00:00
updateScrollbar ( ) ;
}
2015-12-12 13:49:16 +00:00
bool hideTitle = windows [ " hide-subview " ] . isTrue ( ) & &
2014-10-27 07:57:18 +00:00
mSubViews . size ( ) = = 1 & & ! mSubViews . at ( 0 ) - > isFloating ( ) ;
updateTitle ( ) ;
2019-10-06 11:39:27 +00:00
for ( SubView * subView : mSubViews )
2014-09-23 07:01:08 +00:00
{
2014-10-27 07:57:18 +00:00
if ( ! subView - > isFloating ( ) )
2014-09-23 07:01:08 +00:00
{
2014-10-27 07:57:18 +00:00
if ( hideTitle )
2014-09-23 07:01:08 +00:00
{
2014-10-27 07:57:18 +00:00
subView - > setTitleBarWidget ( new QWidget ( this ) ) ;
subView - > setWindowTitle ( QString : : fromUtf8 ( subView - > getTitle ( ) . c_str ( ) ) ) ;
}
else
2014-09-23 07:01:08 +00:00
{
2014-10-27 07:57:18 +00:00
delete subView - > titleBarWidget ( ) ;
2018-10-09 06:21:12 +00:00
subView - > setTitleBarWidget ( nullptr ) ;
2014-09-23 07:01:08 +00:00
}
}
}
}
2012-11-22 23:51:04 +00:00
void CSVDoc : : View : : updateActions ( )
{
2012-12-08 13:44:03 +00:00
bool editing = ! ( mDocument - > getState ( ) & CSMDoc : : State_Locked ) ;
2014-09-02 09:59:04 +00:00
bool running = mDocument - > getState ( ) & CSMDoc : : State_Running ;
2012-11-22 23:51:04 +00:00
for ( std : : vector < QAction * > : : iterator iter ( mEditingActions . begin ( ) ) ; iter ! = mEditingActions . end ( ) ; + + iter )
( * iter ) - > setEnabled ( editing ) ;
2021-01-09 10:03:48 +00:00
mUndo - > setEnabled ( editing & & mDocument - > getUndoStack ( ) . canUndo ( ) ) ;
mRedo - > setEnabled ( editing & & mDocument - > getUndoStack ( ) . canRedo ( ) ) ;
2012-11-23 09:52:46 +00:00
2014-09-02 09:59:04 +00:00
mSave - > setEnabled ( ! ( mDocument - > getState ( ) & CSMDoc : : State_Saving ) & & ! running ) ;
2012-12-08 13:44:03 +00:00
mVerify - > setEnabled ( ! ( mDocument - > getState ( ) & CSMDoc : : State_Verifying ) ) ;
2014-09-02 09:56:35 +00:00
2014-09-04 15:45:43 +00:00
mGlobalDebugProfileMenu - > updateActions ( running ) ;
2014-09-02 09:59:04 +00:00
mStopDebug - > setEnabled ( running ) ;
2015-08-06 10:52:10 +00:00
2015-08-08 14:47:58 +00:00
mMerge - > setEnabled ( mDocument - > getContentFiles ( ) . size ( ) > 1 & &
! ( mDocument - > getState ( ) & CSMDoc : : State_Merging ) ) ;
2012-11-22 23:51:04 +00:00
}
2013-03-02 15:22:44 +00:00
CSVDoc : : View : : View ( ViewManager & viewManager , CSMDoc : : Document * document , int totalViews )
2013-03-02 13:57:41 +00:00
: mViewManager ( viewManager ) , mDocument ( document ) , mViewIndex ( totalViews - 1 ) ,
2018-10-09 06:21:12 +00:00
mViewTotal ( totalViews ) , mScroll ( nullptr ) , mScrollbarOnly ( false )
2012-11-22 12:30:02 +00:00
{
2015-12-12 13:49:16 +00:00
CSMPrefs : : Category & windows = CSMPrefs : : State : : get ( ) [ " Windows " ] ;
2015-01-15 01:49:54 +00:00
2015-12-12 13:49:16 +00:00
int width = std : : max ( windows [ " default-width " ] . toInt ( ) , 300 ) ;
int height = std : : max ( windows [ " default-height " ] . toInt ( ) , 300 ) ;
2013-06-20 23:06:25 +00:00
2015-05-30 10:05:35 +00:00
resize ( width , height ) ;
2012-11-22 14:09:04 +00:00
2013-03-11 11:38:27 +00:00
mSubViewWindow . setDockOptions ( QMainWindow : : AllowNestedDocks ) ;
2015-12-12 13:49:16 +00:00
if ( windows [ " mainwindow-scrollbar " ] . toString ( ) = = " Grow Only " )
2015-05-17 10:45:13 +00:00
{
setCentralWidget ( & mSubViewWindow ) ;
}
else
{
2016-02-01 11:39:24 +00:00
createScrollArea ( ) ;
2015-05-17 10:45:13 +00:00
}
2013-02-23 03:53:32 +00:00
2012-11-23 11:20:35 +00:00
mOperations = new Operations ;
addDockWidget ( Qt : : BottomDockWidgetArea , mOperations ) ;
2015-10-08 19:29:50 +00:00
setContextMenuPolicy ( Qt : : NoContextMenu ) ;
2012-11-22 14:09:04 +00:00
updateTitle ( ) ;
2012-11-22 13:49:58 +00:00
setupUi ( ) ;
2012-11-26 11:29:22 +00:00
2014-09-04 08:47:30 +00:00
updateActions ( ) ;
2012-12-11 12:22:43 +00:00
CSVWorld : : addSubViewFactories ( mSubViewFactory ) ;
2012-12-11 14:35:47 +00:00
CSVTools : : addSubViewFactories ( mSubViewFactory ) ;
2013-02-23 03:53:32 +00:00
2014-09-05 11:49:34 +00:00
mSubViewFactory . add ( CSMWorld : : UniversalId : : Type_RunLog , new SubViewFactory < RunLogSubView > ) ;
2022-08-23 02:28:58 +00:00
connect ( mOperations , & Operations : : abortOperation , this , & View : : abortOperation ) ;
2015-12-15 09:40:00 +00:00
2022-08-23 02:28:58 +00:00
connect ( & CSMPrefs : : State : : get ( ) , & CSMPrefs : : State : : settingChanged ,
this , & View : : settingChanged ) ;
2012-11-26 11:29:22 +00:00
}
CSVDoc : : View : : ~ View ( )
{
2012-11-22 13:10:23 +00:00
}
const CSMDoc : : Document * CSVDoc : : View : : getDocument ( ) const
{
return mDocument ;
}
CSMDoc : : Document * CSVDoc : : View : : getDocument ( )
{
return mDocument ;
2012-11-22 13:49:58 +00:00
}
2012-11-22 14:09:04 +00:00
void CSVDoc : : View : : setIndex ( int viewIndex , int totalViews )
{
mViewIndex = viewIndex ;
mViewTotal = totalViews ;
updateTitle ( ) ;
}
2012-11-22 22:42:17 +00:00
void CSVDoc : : View : : updateDocumentState ( )
{
updateTitle ( ) ;
2012-11-22 23:51:04 +00:00
updateActions ( ) ;
2012-11-23 11:20:35 +00:00
static const int operations [ ] =
{
2015-03-27 15:33:54 +00:00
CSMDoc : : State_Saving , CSMDoc : : State_Verifying , CSMDoc : : State_Searching ,
2015-07-30 09:49:24 +00:00
CSMDoc : : State_Merging ,
2012-11-23 11:20:35 +00:00
- 1 // end marker
} ;
int state = mDocument - > getState ( ) ;
for ( int i = 0 ; operations [ i ] ! = - 1 ; + + i )
if ( ! ( state & operations [ i ] ) )
2013-02-23 03:53:32 +00:00
mOperations - > quitOperation ( operations [ i ] ) ;
2012-11-30 12:58:10 +00:00
2012-12-11 12:22:43 +00:00
QList < CSVDoc : : SubView * > subViews = findChildren < CSVDoc : : SubView * > ( ) ;
2012-11-30 12:58:10 +00:00
2012-12-11 12:22:43 +00:00
for ( QList < CSVDoc : : SubView * > : : iterator iter ( subViews . begin ( ) ) ; iter ! = subViews . end ( ) ; + + iter )
2012-12-08 13:44:03 +00:00
( * iter ) - > setEditLock ( state & CSMDoc : : State_Locked ) ;
2012-11-22 22:42:17 +00:00
}
2012-11-23 11:20:35 +00:00
void CSVDoc : : View : : updateProgress ( int current , int max , int type , int threads )
2012-11-23 09:25:34 +00:00
{
2012-11-23 11:20:35 +00:00
mOperations - > setProgress ( current , max , type , threads ) ;
2012-11-23 09:25:34 +00:00
}
2014-03-02 12:29:02 +00:00
void CSVDoc : : View : : addSubView ( const CSMWorld : : UniversalId & id , const std : : string & hint )
2012-11-24 12:17:21 +00:00
{
2015-12-12 13:49:16 +00:00
CSMPrefs : : Category & windows = CSMPrefs : : State : : get ( ) [ " Windows " ] ;
2012-11-24 12:17:21 +00:00
2014-11-20 19:48:42 +00:00
bool isReferenceable = id . getClass ( ) = = CSMWorld : : UniversalId : : Class_RefRecord ;
2014-09-24 03:49:19 +00:00
// User setting to reuse sub views (on a per top level view basis)
2015-12-12 13:49:16 +00:00
if ( windows [ " reuse " ] . isTrue ( ) )
2014-09-24 03:49:19 +00:00
{
2019-10-06 11:39:27 +00:00
for ( SubView * sb : mSubViews )
2014-09-24 03:49:19 +00:00
{
2014-11-19 08:10:29 +00:00
bool isSubViewReferenceable =
sb - > getUniversalId ( ) . getType ( ) = = CSMWorld : : UniversalId : : Type_Referenceable ;
2014-11-20 19:48:42 +00:00
if ( ( isReferenceable & & isSubViewReferenceable & & id . getId ( ) = = sb - > getUniversalId ( ) . getId ( ) )
2014-11-19 08:10:29 +00:00
| |
( ! isReferenceable & & id = = sb - > getUniversalId ( ) ) )
2014-09-24 03:49:19 +00:00
{
2014-11-20 19:48:42 +00:00
sb - > setFocus ( ) ;
2015-03-16 02:07:37 +00:00
if ( ! hint . empty ( ) )
sb - > useHint ( hint ) ;
2014-09-24 03:49:19 +00:00
return ;
}
}
}
2015-05-29 04:07:41 +00:00
if ( mScroll )
2022-08-23 02:28:58 +00:00
QObject : : connect ( mScroll - > horizontalScrollBar ( ) , & QScrollBar : : rangeChanged ,
this , & View : : moveScrollBarToEnd ) ;
2015-05-29 04:07:41 +00:00
2014-09-24 03:49:19 +00:00
// User setting for limiting the number of sub views per top level view.
// Automatically open a new top level view if this number is exceeded
//
// If the sub view limit setting is one, the sub view title bar is hidden and the
// text in the main title bar is adjusted accordingly
2015-12-12 13:49:16 +00:00
if ( mSubViews . size ( ) > = windows [ " max-subviews " ] . toInt ( ) ) // create a new top level view
2014-09-23 07:01:08 +00:00
{
mViewManager . addView ( mDocument , id , hint ) ;
return ;
}
2012-11-24 12:17:21 +00:00
2018-10-09 06:21:12 +00:00
SubView * view = nullptr ;
2014-11-20 19:48:42 +00:00
if ( isReferenceable )
2014-03-11 12:02:25 +00:00
{
view = mSubViewFactory . makeSubView ( CSMWorld : : UniversalId ( CSMWorld : : UniversalId : : Type_Referenceable , id . getId ( ) ) , * mDocument ) ;
2014-09-23 10:51:14 +00:00
}
else
2014-03-11 12:02:25 +00:00
{
view = mSubViewFactory . makeSubView ( id , * mDocument ) ;
}
assert ( view ) ;
2022-04-28 17:52:02 +00:00
view - > setParent ( this ) ;
2018-07-21 15:36:50 +00:00
view - > setEditLock ( mDocument - > getState ( ) & CSMDoc : : State_Locked ) ;
2014-09-23 07:01:08 +00:00
mSubViews . append ( view ) ; // only after assert
2014-03-02 12:29:02 +00:00
2015-12-12 13:49:16 +00:00
int minWidth = windows [ " minimum-width " ] . toInt ( ) ;
view - > setMinimumWidth ( minWidth ) ;
2014-09-22 21:16:07 +00:00
2013-07-25 12:29:56 +00:00
view - > setStatusBar ( mShowStatusBar - > isChecked ( ) ) ;
2015-05-17 10:45:13 +00:00
// Work out how to deal with additional subviews
//
// Policy for "Grow then Scroll":
//
// - Increase the horizontal width of the mainwindow until it becomes greater than or equal
// to the screen (monitor) width.
// - Move the mainwindow position sideways if necessary to fit within the screen.
// - Any more additions increases the size of the mSubViewWindow (horizontal scrollbar
// should become visible)
// - Move the scroll bar to the newly added subview
//
2015-12-12 13:49:16 +00:00
mScrollbarOnly = windows [ " mainwindow-scrollbar " ] . toString ( ) = = " Scrollbar Only " ;
2015-05-17 10:45:13 +00:00
2016-01-27 17:50:53 +00:00
updateWidth ( windows [ " grow-limit " ] . isTrue ( ) , minWidth ) ;
2015-05-17 10:45:13 +00:00
2013-03-06 12:41:33 +00:00
mSubViewWindow . addDockWidget ( Qt : : TopDockWidgetArea , view ) ;
2012-12-12 21:36:20 +00:00
2016-02-01 11:12:14 +00:00
updateSubViewIndices ( ) ;
2014-09-23 10:51:14 +00:00
2022-08-23 02:28:58 +00:00
connect ( view , & SubView : : focusId , this , & View : : addSubView ) ;
2012-12-12 21:36:20 +00:00
2022-08-23 02:28:58 +00:00
connect ( view , qOverload < SubView * > ( & SubView : : closeRequest ) ,
this , & View : : closeRequest ) ;
2014-10-25 16:13:56 +00:00
2022-08-23 02:28:58 +00:00
connect ( view , & SubView : : updateTitle , this , & View : : updateTitle ) ;
2014-10-27 07:57:18 +00:00
2022-08-23 02:28:58 +00:00
connect ( view , & SubView : : updateSubViewIndices , this , & View : : updateSubViewIndices ) ;
2013-06-15 11:40:18 +00:00
2019-07-01 23:26:05 +00:00
CSVWorld : : TableSubView * tableView = dynamic_cast < CSVWorld : : TableSubView * > ( view ) ;
if ( tableView )
{
2022-08-23 02:28:58 +00:00
connect ( this , & View : : requestFocus ,
tableView , & CSVWorld : : TableSubView : : requestFocus ) ;
2019-07-01 23:26:05 +00:00
}
CSVWorld : : SceneSubView * sceneView = dynamic_cast < CSVWorld : : SceneSubView * > ( view ) ;
if ( sceneView )
{
2022-08-23 02:28:58 +00:00
connect ( sceneView , & CSVWorld : : SceneSubView : : requestFocus ,
this , & View : : onRequestFocus ) ;
2019-07-01 23:26:05 +00:00
}
2022-04-27 01:31:27 +00:00
if ( CSMPrefs : : State : : get ( ) [ " ID Tables " ] [ " subview-new-window " ] . isTrue ( ) )
{
CSVWorld : : DialogueSubView * dialogueView = dynamic_cast < CSVWorld : : DialogueSubView * > ( view ) ;
if ( dialogueView )
dialogueView - > setFloating ( true ) ;
CSVWorld : : ScriptSubView * scriptView = dynamic_cast < CSVWorld : : ScriptSubView * > ( view ) ;
if ( scriptView )
scriptView - > setFloating ( true ) ;
}
2012-11-24 12:17:21 +00:00
view - > show ( ) ;
2015-03-16 02:07:37 +00:00
if ( ! hint . empty ( ) )
view - > useHint ( hint ) ;
2012-11-24 12:17:21 +00:00
}
2015-05-29 04:07:41 +00:00
void CSVDoc : : View : : moveScrollBarToEnd ( int min , int max )
{
if ( mScroll )
{
mScroll - > horizontalScrollBar ( ) - > setValue ( max ) ;
2022-08-23 02:28:58 +00:00
QObject : : disconnect ( mScroll - > horizontalScrollBar ( ) , & QScrollBar : : rangeChanged ,
this , & View : : moveScrollBarToEnd ) ;
2015-05-29 04:07:41 +00:00
}
}
2015-12-15 09:40:00 +00:00
void CSVDoc : : View : : settingChanged ( const CSMPrefs : : Setting * setting )
{
if ( * setting = = " Windows/hide-subview " )
2018-10-09 06:21:12 +00:00
updateSubViewIndices ( nullptr ) ;
2015-12-15 09:40:00 +00:00
else if ( * setting = = " Windows/mainwindow-scrollbar " )
{
if ( setting - > toString ( ) ! = " Grow Only " )
{
if ( mScroll )
{
if ( setting - > toString ( ) = = " Scrollbar Only " )
{
mScrollbarOnly = true ;
mSubViewWindow . setMinimumWidth ( 0 ) ;
}
else if ( mScrollbarOnly )
{
mScrollbarOnly = false ;
updateScrollbar ( ) ;
}
}
else
{
2016-02-01 11:39:24 +00:00
createScrollArea ( ) ;
2015-12-15 09:40:00 +00:00
}
}
else if ( mScroll )
{
mScroll - > takeWidget ( ) ;
setCentralWidget ( & mSubViewWindow ) ;
mScroll - > deleteLater ( ) ;
2018-10-09 06:21:12 +00:00
mScroll = nullptr ;
2015-12-15 09:40:00 +00:00
}
}
}
2012-11-22 13:49:58 +00:00
void CSVDoc : : View : : newView ( )
{
mViewManager . addView ( mDocument ) ;
2012-11-22 15:00:23 +00:00
}
2012-11-22 23:36:01 +00:00
void CSVDoc : : View : : save ( )
{
mDocument - > save ( ) ;
2012-11-23 12:15:45 +00:00
}
2020-04-18 20:54:21 +00:00
void CSVDoc : : View : : openHelp ( )
{
Misc : : HelpViewer : : openHelp ( " manuals/openmw-cs/index.html " ) ;
}
void CSVDoc : : View : : tutorial ( )
{
Misc : : HelpViewer : : openHelp ( " manuals/openmw-cs/tour.html " ) ;
}
2018-12-21 12:17:09 +00:00
void CSVDoc : : View : : infoAbout ( )
{
// Get current OpenMW version
2022-06-19 11:28:33 +00:00
QString versionInfo = ( Version : : getOpenmwVersionDescription ( mDocument - > getResourceDir ( ) ) +
2018-12-21 12:17:09 +00:00
# if defined(__x86_64__) || defined(_M_X64)
" (64-bit) " ) . c_str ( ) ;
# else
" (32-bit) " ) . c_str ( ) ;
# endif
// Get current year
2020-11-13 07:39:47 +00:00
time_t now = time ( nullptr ) ;
2018-12-21 12:17:09 +00:00
struct tm tstruct ;
char copyrightInfo [ 40 ] ;
tstruct = * localtime ( & now ) ;
strftime ( copyrightInfo , sizeof ( copyrightInfo ) , " Copyright © 2008-%Y OpenMW Team " , & tstruct ) ;
QString aboutText = QString (
" <p style= \" white-space: pre-wrap; \" > "
" <b><h2>OpenMW Construction Set</h2></b> "
" %1 \n \n "
" %2 \n \n "
" %3 \n \n "
" <table> "
" <tr><td>%4</td><td><a href= \" https://openmw.org \" >https://openmw.org</a></td></tr> "
" <tr><td>%5</td><td><a href= \" https://forum.openmw.org \" >https://forum.openmw.org</a></td></tr> "
" <tr><td>%6</td><td><a href= \" https://gitlab.com/OpenMW/openmw/issues \" >https://gitlab.com/OpenMW/openmw/issues</a></td></tr> "
2021-05-31 20:11:43 +00:00
" <tr><td>%7</td><td><a href= \" https://web.libera.chat/#openmw \" >ircs://irc.libera.chat/#openmw</a></td></tr> "
2018-12-21 12:17:09 +00:00
" </table> "
" </p> " )
. arg ( versionInfo
, tr ( " OpenMW-CS is a content file editor for OpenMW, a modern, free and open source game engine. " )
, tr ( copyrightInfo )
, tr ( " Home Page: " )
, tr ( " Forum: " )
, tr ( " Bug Tracker: " )
, tr ( " IRC: " ) ) ;
QMessageBox : : about ( this , " About OpenMW-CS " , aboutText ) ;
}
void CSVDoc : : View : : infoAboutQt ( )
{
QMessageBox : : aboutQt ( this ) ;
}
2012-11-23 12:15:45 +00:00
void CSVDoc : : View : : verify ( )
{
2012-12-11 14:35:47 +00:00
addSubView ( mDocument - > verify ( ) ) ;
2012-11-24 12:17:21 +00:00
}
2012-11-26 11:29:22 +00:00
void CSVDoc : : View : : addGlobalsSubView ( )
2012-11-24 12:17:21 +00:00
{
2012-11-26 11:29:22 +00:00
addSubView ( CSMWorld : : UniversalId : : Type_Globals ) ;
2013-02-08 08:58:19 +00:00
}
void CSVDoc : : View : : addGmstsSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_Gmsts ) ;
2013-02-23 03:53:32 +00:00
}
2013-03-21 13:31:32 +00:00
void CSVDoc : : View : : addSkillsSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_Skills ) ;
}
2013-03-25 12:22:06 +00:00
void CSVDoc : : View : : addClassesSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_Classes ) ;
}
2013-04-02 10:00:45 +00:00
void CSVDoc : : View : : addFactionsSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_Factions ) ;
}
2013-04-04 12:34:39 +00:00
void CSVDoc : : View : : addRacesSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_Races ) ;
}
2013-04-06 19:21:10 +00:00
void CSVDoc : : View : : addSoundsSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_Sounds ) ;
}
2013-04-07 13:17:35 +00:00
void CSVDoc : : View : : addScriptsSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_Scripts ) ;
}
2013-04-07 14:32:06 +00:00
void CSVDoc : : View : : addRegionsSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_Regions ) ;
}
2013-04-07 18:26:39 +00:00
void CSVDoc : : View : : addBirthsignsSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_Birthsigns ) ;
}
2013-04-09 09:40:36 +00:00
void CSVDoc : : View : : addSpellsSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_Spells ) ;
}
2013-04-14 15:04:55 +00:00
void CSVDoc : : View : : addCellsSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_Cells ) ;
}
2013-05-11 15:01:16 +00:00
void CSVDoc : : View : : addReferenceablesSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_Referenceables ) ;
}
2013-07-06 15:03:18 +00:00
void CSVDoc : : View : : addReferencesSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_References ) ;
}
2013-07-08 11:12:50 +00:00
void CSVDoc : : View : : addRegionMapSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_RegionMap ) ;
}
2013-07-22 19:18:47 +00:00
void CSVDoc : : View : : addFiltersSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_Filters ) ;
}
2013-10-20 15:13:31 +00:00
void CSVDoc : : View : : addTopicsSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_Topics ) ;
}
void CSVDoc : : View : : addJournalsSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_Journals ) ;
}
2013-10-29 12:18:22 +00:00
void CSVDoc : : View : : addTopicInfosSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_TopicInfos ) ;
}
void CSVDoc : : View : : addJournalInfosSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_JournalInfos ) ;
}
2014-06-30 18:40:34 +00:00
void CSVDoc : : View : : addEnchantmentsSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_Enchantments ) ;
}
2014-07-01 10:37:22 +00:00
void CSVDoc : : View : : addBodyPartsSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_BodyParts ) ;
}
2014-09-23 11:21:54 +00:00
void CSVDoc : : View : : addSoundGensSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_SoundGens ) ;
}
2014-07-05 13:51:17 +00:00
void CSVDoc : : View : : addMeshesSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_Meshes ) ;
}
void CSVDoc : : View : : addIconsSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_Icons ) ;
}
void CSVDoc : : View : : addMusicsSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_Musics ) ;
}
void CSVDoc : : View : : addSoundsResSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_SoundsRes ) ;
}
2014-09-26 11:12:17 +00:00
void CSVDoc : : View : : addMagicEffectsSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_MagicEffects ) ;
}
2014-07-05 13:51:17 +00:00
void CSVDoc : : View : : addTexturesSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_Textures ) ;
}
void CSVDoc : : View : : addVideosSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_Videos ) ;
}
2014-08-04 11:36:01 +00:00
void CSVDoc : : View : : addDebugProfilesSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_DebugProfiles ) ;
}
2014-09-05 11:49:34 +00:00
void CSVDoc : : View : : addRunLogSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_RunLog ) ;
}
2017-08-24 21:12:15 +00:00
void CSVDoc : : View : : addLandsSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_Lands ) ;
}
void CSVDoc : : View : : addLandTexturesSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_LandTextures ) ;
}
2014-10-02 13:16:19 +00:00
void CSVDoc : : View : : addPathgridSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_Pathgrids ) ;
}
2015-03-03 13:32:12 +00:00
void CSVDoc : : View : : addStartScriptsSubView ( )
{
addSubView ( CSMWorld : : UniversalId : : Type_StartScripts ) ;
}
2015-03-17 11:30:47 +00:00
void CSVDoc : : View : : addSearchSubView ( )
{
addSubView ( mDocument - > newSearch ( ) ) ;
}
2015-06-26 14:11:00 +00:00
void CSVDoc : : View : : addMetaDataSubView ( )
{
addSubView ( CSMWorld : : UniversalId ( CSMWorld : : UniversalId : : Type_MetaData , " sys::meta " ) ) ;
}
2013-02-23 03:53:32 +00:00
void CSVDoc : : View : : abortOperation ( int type )
{
mDocument - > abortOperation ( type ) ;
updateActions ( ) ;
}
2013-03-06 12:41:33 +00:00
CSVDoc : : Operations * CSVDoc : : View : : getOperations ( ) const
2013-02-23 03:53:32 +00:00
{
return mOperations ;
}
2013-03-12 11:28:13 +00:00
void CSVDoc : : View : : exit ( )
{
emit exitApplicationRequest ( this ) ;
}
2013-05-16 16:04:55 +00:00
2013-06-20 23:06:25 +00:00
void CSVDoc : : View : : resizeViewWidth ( int width )
2013-05-08 01:33:42 +00:00
{
2013-06-20 23:06:25 +00:00
if ( width > = 0 )
resize ( width , geometry ( ) . height ( ) ) ;
}
2013-05-08 01:33:42 +00:00
2013-06-20 23:06:25 +00:00
void CSVDoc : : View : : resizeViewHeight ( int height )
{
if ( height > = 0 )
resize ( geometry ( ) . width ( ) , height ) ;
}
2013-05-08 01:33:42 +00:00
2013-07-25 12:29:56 +00:00
void CSVDoc : : View : : toggleShowStatusBar ( bool show )
{
2019-10-06 11:39:27 +00:00
for ( QObject * view : mSubViewWindow . children ( ) )
2013-07-25 12:29:56 +00:00
{
if ( CSVDoc : : SubView * subView = dynamic_cast < CSVDoc : : SubView * > ( view ) )
subView - > setStatusBar ( show ) ;
}
}
2014-05-10 10:04:36 +00:00
2014-09-18 06:05:32 +00:00
void CSVDoc : : View : : toggleStatusBar ( bool checked )
{
mShowStatusBar - > setChecked ( checked ) ;
}
2014-05-10 10:04:36 +00:00
void CSVDoc : : View : : loadErrorLog ( )
{
addSubView ( CSMWorld : : UniversalId ( CSMWorld : : UniversalId : : Type_LoadErrorLog , 0 ) ) ;
}
2014-09-02 08:21:17 +00:00
2014-09-04 15:45:43 +00:00
void CSVDoc : : View : : run ( const std : : string & profile , const std : : string & startupInstruction )
2014-09-02 08:21:17 +00:00
{
2014-09-04 15:45:43 +00:00
mDocument - > startRunning ( profile , startupInstruction ) ;
2014-09-02 08:21:17 +00:00
}
void CSVDoc : : View : : stop ( )
{
mDocument - > stopRunning ( ) ;
2014-09-14 04:04:47 +00:00
}
2014-10-25 16:13:56 +00:00
void CSVDoc : : View : : closeRequest ( SubView * subView )
{
2015-12-12 13:49:16 +00:00
CSMPrefs : : Category & windows = CSMPrefs : : State : : get ( ) [ " Windows " ] ;
2014-10-27 07:57:18 +00:00
2015-12-12 13:49:16 +00:00
if ( mSubViews . size ( ) > 1 | | mViewTotal < = 1 | | ! windows [ " hide-subview " ] . isTrue ( ) )
2015-05-17 12:27:17 +00:00
{
2014-10-25 16:13:56 +00:00
subView - > deleteLater ( ) ;
2015-05-17 12:27:17 +00:00
mSubViews . removeOne ( subView ) ;
}
2014-10-25 16:13:56 +00:00
else if ( mViewManager . closeRequest ( this ) )
mViewManager . removeDocAndView ( mDocument ) ;
2014-10-27 08:56:52 +00:00
}
2015-05-17 10:45:13 +00:00
void CSVDoc : : View : : updateScrollbar ( )
{
QRect rect ;
QWidget * topLevel = QApplication : : topLevelAt ( pos ( ) ) ;
if ( topLevel )
rect = topLevel - > rect ( ) ;
else
rect = this - > rect ( ) ;
int newWidth = 0 ;
for ( int i = 0 ; i < mSubViews . size ( ) ; + + i )
{
newWidth + = mSubViews [ i ] - > width ( ) ;
}
int frameWidth = frameGeometry ( ) . width ( ) - width ( ) ;
if ( ( newWidth + frameWidth ) > = rect . width ( ) )
mSubViewWindow . setMinimumWidth ( newWidth ) ;
else
mSubViewWindow . setMinimumWidth ( 0 ) ;
}
2015-08-06 10:52:10 +00:00
void CSVDoc : : View : : merge ( )
{
emit mergeDocument ( mDocument ) ;
}
2016-01-27 17:50:53 +00:00
void CSVDoc : : View : : updateWidth ( bool isGrowLimit , int minSubViewWidth )
{
QDesktopWidget * dw = QApplication : : desktop ( ) ;
QRect rect ;
if ( isGrowLimit )
rect = dw - > screenGeometry ( this ) ;
else
2019-12-20 09:36:32 +00:00
rect = QGuiApplication : : screens ( ) . at ( dw - > screenNumber ( this ) ) - > geometry ( ) ;
2016-01-27 17:50:53 +00:00
if ( ! mScrollbarOnly & & mScroll & & mSubViews . size ( ) > 1 )
{
int newWidth = width ( ) + minSubViewWidth ;
int frameWidth = frameGeometry ( ) . width ( ) - width ( ) ;
if ( newWidth + frameWidth < = rect . width ( ) )
{
resize ( newWidth , height ( ) ) ;
// WARNING: below code assumes that new subviews are added to the right
if ( x ( ) > rect . width ( ) - ( newWidth + frameWidth ) )
move ( rect . width ( ) - ( newWidth + frameWidth ) , y ( ) ) ; // shift left to stay within the screen
}
else
{
// full width
resize ( rect . width ( ) - frameWidth , height ( ) ) ;
mSubViewWindow . setMinimumWidth ( mSubViewWindow . width ( ) + minSubViewWidth ) ;
move ( 0 , y ( ) ) ;
}
}
}
2016-02-01 11:39:24 +00:00
void CSVDoc : : View : : createScrollArea ( )
{
mScroll = new QScrollArea ( this ) ;
mScroll - > setWidgetResizable ( true ) ;
mScroll - > setWidget ( & mSubViewWindow ) ;
setCentralWidget ( mScroll ) ;
}
2019-07-01 23:26:05 +00:00
void CSVDoc : : View : : onRequestFocus ( const std : : string & id )
{
if ( CSMPrefs : : get ( ) [ " 3D Scene Editing " ] [ " open-list-view " ] . isTrue ( ) )
{
addReferencesSubView ( ) ;
emit requestFocus ( id ) ;
}
else
{
addSubView ( CSMWorld : : UniversalId ( CSMWorld : : UniversalId : : Type_Reference , id ) ) ;
}
}