1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
|
/************************************************************************
**
** Copyright (C) 2019-2020 Kevin B. Hendricks, Stratford Ontario Canada
**
** This file is part of PageEdit.
**
** PageEdit is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** PageEdit is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with PageEdit. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#pragma once
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ui_main.h"
#include <QtCore/QSignalMapper>
#include <QMap>
#include <QtWebEngineWidgets/QWebEngineView>
#include <QMainWindow>
#include <QMoveEvent>
#include <QCloseEvent>
#include <QResizeEvent>
#include <Viewer.h>
#include <Inspector.h>
#include "ElementIndex.h"
class WebViewEdit;
class Inspector;
class QWebEngineView;
class QVBoxLayout;
class QHBoxLayout;
class QSlider;
class QLabel;
class SelectCharacter;
class SearchToolbar;
const int STATUSBAR_MSG_DISPLAY_TIME = 7000;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QString filepath, QWidget *parent = 0);
~MainWindow();
QList<ElementIndex> GetCaretLocation();
bool IsVisible();
bool HasFocus();
bool eventFilter(QObject *object, QEvent *event);
// void setMathJaxURL(QString mathjaxurl) { m_mathjaxurl = mathjaxurl; };
void setUserCSSURL(QString usercssurl) { m_usercssurl = usercssurl; }
void ExtendIconSizes();
// Zoom Related
float GetZoomFactor();
int ZoomFactorToSliderRange(float zoom_factor);
float SliderRangeToZoomFactor(int slider_range_value);
void ZoomByStep(bool zoom_in);
void ZoomByFactor(float new_zoom_factor);
QString GetSandBoxPath() { return m_SandBoxPath; };
public slots:
// Zoom Related
void ZoomIn();
void ZoomOut();
void ZoomReset();
void SliderZoom(int slider_value);
void UpdateZoomSlider(float new_zoom_factor);
void UpdateZoomLabel(int slider_value);
void UpdateZoomLabel(float new_zoom_factor);
// General Slots
void DoUpdatePage();
void UpdatePage(const QString &filename, const QString &source="");
void RefreshPage();
void UpdateWindowTitle();
void ScrollTo(QList<ElementIndex> location);
void SetZoomFactor(float factor);
void EmitGoToPreviewLocationRequest();
void InspectPreviewPage();
void SelectAllPreview();
void CopyPreview();
void ReloadPreview();
void ShowMessageOnStatusBar(const QString &message = "", int millisecond_duration = STATUSBAR_MSG_DISPLAY_TIME);
void AboutPageEdit();
// Navigation Slots
void EditNext();
void EditPrev();
void CBNavigateActivated(int index);
void LinkClicked(const QUrl &url);
void LinkReturn();
// Utility routines
QString GetCurrentFilePath();
QStringList GetAllFilePaths(int skip = -1);
// Mode slots
void ToggleMode(bool on);
static const QMap<QString, QString> GetLoadFiltersMap();
static const QMap<QString, QString> GetSaveFiltersMap();
// GUI slots
void sizeMenuIcons();
void SelectionChanged();
void CheckHeadingLevel(const QString &element_name);
void ApplyHeadingToSelection(const QString &heading_type);
void SetPreserveHeadingAttributes(bool new_state);
bool Save();
bool SaveAs();
void Open();
void Exit();
void Undo();
void Redo();
void Cut();
void Copy();
void SelectAll();
void Paste();
void PasteText(const QString& text);
void PreferencesDialog();
void SearchOnPage();
void InsertSpecialCharacter();
void InsertSGFSectionMarker();
void InsertBulletedList();
void InsertNumberedList();
void InsertId();
void InsertHyperlink();
void InsertFileDialog();
void InsertFiles(const QStringList &selected_files);
void Bold();
void Italic();
void Underline();
void Strikethrough();
void Subscript();
void Superscript();
void AlignLeft();
void AlignCenter();
void AlignRight();
void AlignJustify();
void DecreaseIndent();
void IncreaseIndent();
void UpdateActionState();
void ChangeCasing(int casing_mode);
// void ToggleSpellCheck();
void ApplicationPaletteChanged();
signals:
void Shown();
void ZoomFactorChanged(float factor);
void GoToPreviewLocationRequest();
void RequestPreviewReload();
/**
* Emitted whenever m_WebView wants to open an URL.
* @param url The URL to open.
*/
void OpenUrlRequest(const QUrl &url);
protected:
virtual void hideEvent(QHideEvent* event);
virtual void showEvent(QShowEvent* event);
void resizeEvent(QResizeEvent * event);
void moveEvent(QMoveEvent *event);
void closeEvent(QCloseEvent * event);
bool MaybeSaveDialogSaysProceed(bool modified);
QString GetCleanHtml();
QString GetSource();
QString GetHTMLToPaste(const QString & hmtl_snippet);
private:
void SetupView();
void SetupFileList(const QString& filepath);
void SetupNavigationComboBox();
void LoadSettings();
void SaveSettings();
void AllowSaveIfModified();
void ConnectSignalsToSlots();
WebViewEdit *m_WebView;
Inspector *m_Inspector;
QString m_Filepath;
bool m_GoToRequestPending;
bool m_MouseReleaseEventHappened;
// QString m_mathjaxurl;
QString m_usercssurl;
QSignalMapper *m_headingMapper;
QSignalMapper *m_casingChangeMapper;
bool m_preserveHeadingAttributes;
QString m_CurrentFilePath;
SelectCharacter* m_SelectCharacter;
QSlider *m_slZoomSlider;
QLabel *m_lbZoomLabel;
bool m_updateActionStatePending;
QByteArray m_LastWindowSize;
QString m_LastFolderOpen;
bool m_using_wsprewrap;
SearchToolbar * m_search;
QVBoxLayout * m_layout;
QString m_source;
QStringList m_SpineList;
QString m_Base;
int m_ListPtr;
bool m_UpdatePageInProgress;
QStringList m_MediaList;
QStringList m_MediaKind;
QString m_MediaBase;
QString m_SandBoxPath;
QList<ElementIndex> m_LastLocation;
int m_LastPtr;
Ui::MainWindow ui;
};
#endif // MAINWINDOW_H
|