Skip to content

Commit

Permalink
Chinchilla Functionality (#33)
Browse files Browse the repository at this point in the history
* CodeWidget.h declares the interface for a code editing widget
* CodeWidget.cpp defines an implementation of code widget common to all other implementations
* CodeWidgetPlain.cpp defines an implementation of code widget using QPlainTextEdit
* CodeWidgetScintilla.cpp defines an implementation of code widget using QScintilla
* Changed the CMake lists and qmake pro file to link print support, but it doesn't work for some reason in the AppVeyor build
* Uses widget promotion to add the code widget to the code editor, which script editor derives from
* Now serializes with the main window settings whether tabbed view was enabled, and automatically restores that when you reopen RGM
* Changed tabbed view to use non-expanding tab headers, because not just Rusky but everyone else prefers that including me (applied when switching into tabbed mode)
* Uses qmake `CONFIG` (usable in qmake conditionals) instead of `DEFINES` (available to preprocessor/do not want) to toggle syntax highlighting enabled build
* Disabled the context help button for all windows by default using `Qt::AA_DisableWindowContextHelpButton` (this is silly, Qt should have always been that way). If we decide to use that and have a QWhatsThis or whatever, then it should be overriden on a per window or dialog basis for where we provide the behavior.
* Gave the main window's toolbar a window title "Toolbar" so that you can discern what it is when right-clicking the toolbar or menubar to hide/show docks.
* Made the "Cascade" and "Tile" actions first switch to MDI mode so the tab headers aren't still visible, because they shouldn't be
* Added actions to the "Window" menu to switch active windows. This is primarily oriented at MDI users, to facilitate switching windows when maximized, but can also be used by TDI users because the added mnemonics facilitate faster switching. Further, Notepad++ even has this behavior in its "Window" menu and it's a TDI as well, so definitely a good argument for bringing this back from LGM. The alternative I had experimented with but later decided against was switching into tabbed mode when maximizing an MDI window. I decided against that because it's unnatural and does not meet the established expectations of MDI users.
* Improved the efficiency of model synchronization with ImmediateMapper by removing and readding the widget changed notification connection while updating the model. Without this the script editor would lag because the code widget would constantly be reloaded because changing the code widget would trigger a model update which triggered a widget update and so on.
* Implemented the "Close All Others" action under the "Window" menu which closes every subwindow or tab except the active one.
  • Loading branch information
RobertBColton authored Oct 7, 2018
1 parent 28f195c commit 737a04e
Show file tree
Hide file tree
Showing 20 changed files with 875 additions and 47 deletions.
35 changes: 23 additions & 12 deletions CmakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ set(RGM_SOURCES
MainWindow.cpp
Dialogs/PreferencesDialog.cpp
Editors/BaseEditor.cpp
Editors/CodeEditor.cpp
Editors/BackgroundEditor.cpp
Editors/ObjectEditor.cpp
Editors/SoundEditor.cpp
Editors/ScriptEditor.cpp
Editors/FontEditor.cpp
Editors/PathEditor.cpp
Editors/TimelineEditor.cpp
Expand All @@ -43,6 +45,7 @@ set(RGM_SOURCES
Components/Utility.cpp
Components/RecentFiles.cpp
Widgets/BackgroundRenderer.cpp
Widgets/CodeWidget.cpp
Plugins/RGMPlugin.cpp
Plugins/ServerPlugin.cpp
qtplugins.cpp
Expand All @@ -53,10 +56,12 @@ set(RGM_HEADERS
MainWindow.h
Dialogs/PreferencesDialog.h
Dialogs/PreferencesKeys.h
Editors/CodeEditor.h
Editors/BaseEditor.h
Editors/BackgroundEditor.h
Editors/ObjectEditor.h
Editors/SoundEditor.h
Editors/ScriptEditor.h
Editors/FontEditor.h
Editors/PathEditor.h
Editors/TimelineEditor.h
Expand All @@ -79,6 +84,7 @@ set(RGM_UI
MainWindow.ui
Dialogs/PreferencesDialog.ui
Dialogs/AddImageDialog.ui
Editors/CodeEditor.ui
Editors/BackgroundEditor.ui
Editors/ObjectEditor.ui
Editors/FontEditor.ui
Expand All @@ -94,14 +100,15 @@ set(RGM_RC
)

# Check for QScintilla
set(EDITOR_SOURCES Widgets/CodeWidgetPlain.cpp)
#find_package(QScintilla)
#if (QSCINTILLA_FOUND)
# set(EDITOR_SOURCES Widgets/CodeWidgetScintilla.cpp)
#endif()
find_library(LIB_QSCINTILLA NAMES qscintilla2)
if (NOT LIB_QSCINTILLA)
set(EDITOR_SOURCES Widgets/CodeWidgetPlain.cpp)
else()
set(EDITOR_SOURCES Widgets/CodeWidgetScintilla.cpp)
endif()

# Tell CMake to create the RadialGM executable
add_executable(${EXE} WIN32 ${RGM_UI} ${RGM_HEADERS} ${RGM_SOURCES} ${RGM_RC})
add_executable(${EXE} WIN32 ${RGM_UI} ${RGM_HEADERS} ${RGM_SOURCES} ${EDITOR_SOURCES} ${RGM_RC})

message(STATUS "Initial build flags:")
set(CompilerFlags
Expand All @@ -119,9 +126,9 @@ foreach(CompilerFlag ${CompilerFlags})
message(STATUS " '${CompilerFlag}': ${${CompilerFlag}}")
endforeach()

#if (QSCINTILLA_FOUND)
# target_link_libraries(${EXE} PRIVATE qscintilla)
#endif()
if (LIB_QSCINTILLA)
target_link_libraries(${EXE} PRIVATE ${LIB_QSCINTILLA})
endif()

# Find PugiXML
find_library(LIB_PUGIXML NAMES pugixml)
Expand Down Expand Up @@ -165,28 +172,31 @@ find_package(OpenSSL REQUIRED)
target_link_libraries(${EXE} PRIVATE OpenSSL::SSL OpenSSL::Crypto)

# Find Qt
find_package(Qt5 COMPONENTS Core Widgets Gui REQUIRED)
target_link_libraries(${EXE} PRIVATE Qt5::Core Qt5::WinMain Qt5::Core Qt5::Widgets Qt5::Gui Qt5::Gui)
find_package(Qt5 COMPONENTS Core Widgets Gui PrintSupport REQUIRED)
target_link_libraries(${EXE} PRIVATE Qt5::Core Qt5::WinMain Qt5::Core Qt5::Widgets Qt5::Gui Qt5::Gui Qt5::PrintSupport)

# Debug
find_library(LIB_QT_PLATFORM_D NAMES Qt5PlatformCompositorSupportd)
find_library(LIB_QT_FONT_D NAMES Qt5FontDatabaseSupportd)
find_library(LIB_QT_UI_D NAMES Qt5WindowsUIAutomationSupportd)
find_library(LIB_QT_EVENT_D NAMES Qt5EventDispatcherSupportd)
find_library(LIB_QT_THEME_D NAMES Qt5ThemeSupportd)
find_library(LIB_QT_PRINT_D NAMES Qt5PrintSupportd)
find_library(LIB_QT_ICO_D NAMES qicod PATHS "${QT_DIR}/plugins/imageformats")
find_library(LIB_QT_GIF_D NAMES qgifd PATHS "${QT_DIR}/plugins/imageformats")
find_library(LIB_QT_JPEG_D NAMES qjpegd PATHS "${QT_DIR}/plugins/imageformats")
# Windows 10 SDK doesn't include a debug version of Uxtheme
find_library(LIB_WIN_UXTHEME_D NAMES Uxtheme)
find_library(LIB_QT_WINVISTASTYLE_D NAMES qwindowsvistastyled PATHS "${QT_DIR}/plugins/styles")
find_library(LIB_QT_WIN_D NAMES qwindowsd PATHS "${QT_DIR}/plugins/platforms")

# Release
find_library(LIB_QT_PLATFORM NAMES Qt5PlatformCompositorSupport)
find_library(LIB_QT_FONT NAMES Qt5FontDatabaseSupport)
find_library(LIB_QT_UI NAMES Qt5WindowsUIAutomationSupport)
find_library(LIB_QT_EVENT NAMES Qt5EventDispatcherSupport)
find_library(LIB_QT_THEME NAMES Qt5ThemeSupport)
find_library(LIB_QT_PRINT NAMES Qt5PrintSupport)
# ICO is needed to set Win32 icon on the Window
# also all of these image plugins are very small about 100kb~ each
find_library(LIB_QT_ICO NAMES qico PATHS "${QT_DIR}/plugins/imageformats")
Expand All @@ -201,13 +211,14 @@ target_link_libraries(${EXE} PRIVATE "$<IF:$<CONFIG:Debug>,${LIB_QT_PLATFORM_D},
"$<IF:$<CONFIG:Debug>,${LIB_QT_UI_D},${LIB_QT_UI}>"
"$<IF:$<CONFIG:Debug>,${LIB_QT_EVENT_D},${LIB_QT_EVENT}>"
"$<IF:$<CONFIG:Debug>,${LIB_QT_THEME_D},${LIB_QT_THEME}>"
"$<IF:$<CONFIG:Debug>,${LIB_QT_PRINT_D},${LIB_QT_PRINT}>"
"$<IF:$<CONFIG:Debug>,${LIB_QT_ICO_D},${LIB_QT_ICO}>"
"$<IF:$<CONFIG:Debug>,${LIB_QT_GIF_D},${LIB_QT_GIF}>"
"$<IF:$<CONFIG:Debug>,${LIB_QT_JPEG_D},${LIB_QT_JPEG}>"
"$<IF:$<CONFIG:Debug>,${LIB_WIN_UXTHEME_D},${LIB_WIN_UXTHEME}>"
"$<IF:$<CONFIG:Debug>,${LIB_QT_WINVISTASTYLE_D},${LIB_QT_WINVISTASTYLE}>"
"$<IF:$<CONFIG:Debug>,${LIB_QT_WIN_D},${LIB_QT_WIN}>"
)
)

# Find FreeType
find_package(Freetype REQUIRED)
Expand Down
4 changes: 3 additions & 1 deletion Components/RecentFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ void RecentFiles::updateActions() {
for (; i < count; ++i) {
const QString fileName = QFileInfo(recentFiles.at(i)).fileName();
QString numberString = QString::number(i + 1);
recentFileActs[i]->setText(numberString.insert(numberString.length() - 1, '&') + " " + fileName);
numberString = numberString.insert(numberString.length() - 1, '&');
QString text = tr("%1 %2").arg(numberString).arg(fileName);
recentFileActs[i]->setText(text);
recentFileActs[i]->setData(recentFiles.at(i));
recentFileActs[i]->setVisible(true);
}
Expand Down
34 changes: 34 additions & 0 deletions Editors/CodeEditor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "CodeEditor.h"
#include "ui_CodeEditor.h"

CodeEditor::CodeEditor(ProtoModel *model, QWidget *parent) : BaseEditor(model, parent), ui(new Ui::CodeEditor) {
ui->setupUi(this);

cursorPositionLabel = new QLabel(ui->statusBar);
lineCountLabel = new QLabel(ui->statusBar);

ui->statusBar->addWidget(cursorPositionLabel);
ui->statusBar->addWidget(lineCountLabel);

// make sure we set the status labels at least once
updateCursorPositionLabel();
updateLineCountLabel();

connect(ui->codeWidget, &CodeWidget::cursorPositionChanged, this, &CodeEditor::setCursorPositionLabel);
connect(ui->codeWidget, &CodeWidget::lineCountChanged, this, &CodeEditor::setLineCountLabel);
}

CodeEditor::~CodeEditor() { delete ui; }

void CodeEditor::setCursorPositionLabel(int line, int index) {
this->cursorPositionLabel->setText(tr("Ln %0, Col %1").arg(line).arg(index));
}

void CodeEditor::setLineCountLabel(int lines) { this->lineCountLabel->setText(tr("Lines %0").arg(lines)); }

void CodeEditor::updateCursorPositionLabel() {
auto cursorPosition = this->ui->codeWidget->cursorPosition();
this->setCursorPositionLabel(cursorPosition.first, cursorPosition.second);
}

void CodeEditor::updateLineCountLabel() { this->setLineCountLabel(this->ui->codeWidget->lineCount()); }
32 changes: 32 additions & 0 deletions Editors/CodeEditor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef CODEEDITOR_H
#define CODEEDITOR_H

#include "BaseEditor.h"

#include <QLabel>

namespace Ui {
class CodeEditor;
}

class CodeEditor : public BaseEditor {
Q_OBJECT

public:
explicit CodeEditor(ProtoModel *model, QWidget *parent);
~CodeEditor();

public slots:
void setCursorPositionLabel(int line, int index);
void setLineCountLabel(int lines);
void updateCursorPositionLabel();
void updateLineCountLabel();

protected:
Ui::CodeEditor *ui;

private:
QLabel *cursorPositionLabel, *lineCountLabel;
};

#endif // CODEEDITOR_H
Loading

0 comments on commit 737a04e

Please sign in to comment.