From ae70f6ff733c4642fe3a9f8b3635a0a0b40cf82a Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Tue, 20 Jun 2023 18:47:44 -0500 Subject: [PATCH] Add MRU file list, adjustments to room edge labels. Some edges would be rendered over the in/out/up/down labels attached to them. Now we detect this condition and move them out of the way. --- src/about.cpp | 2 +- src/mainwin.cpp | 149 +++++++++++++++++++++--------------------------- src/mainwin.h | 10 ++++ src/mapview.cpp | 46 +++++++++++++-- 4 files changed, 119 insertions(+), 88 deletions(-) diff --git a/src/about.cpp b/src/about.cpp index d62a929..09708ad 100644 --- a/src/about.cpp +++ b/src/about.cpp @@ -25,7 +25,7 @@ AboutWindow::AboutWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog) "" "" - "" + "" "" "" "" diff --git a/src/mainwin.cpp b/src/mainwin.cpp index b12ab24..186e085 100644 --- a/src/mainwin.cpp +++ b/src/mainwin.cpp @@ -18,7 +18,6 @@ #include "roomwidget.h" #include "undo.h" - // CMainWin #if 0 @@ -49,7 +48,6 @@ static UINT indicators[] = }; #endif - MainWin::MainWin(): settings("Underground Software", "GUEmap") { setCentralWidget(&mdiArea); @@ -105,7 +103,6 @@ MainWin::MainWin(): settings("Underground Software", "GUEmap") } - void MainWin::closeEvent(QCloseEvent * event) { WriteSettings(); @@ -113,7 +110,6 @@ void MainWin::closeEvent(QCloseEvent * event) //Do we have a memory leak here if we don't delete the font in the Object??? } - void MainWin::FileNew(void) { MapView * map = new MapView; @@ -129,7 +125,6 @@ void MainWin::FileNew(void) statusBar()->showMessage(tr("New map created."), 2000); } - void MainWin::FileOpen(void) { QString filename = QFileDialog::getOpenFileName(this, tr("Open Map"), "", @@ -139,6 +134,21 @@ void MainWin::FileOpen(void) if (filename.isEmpty()) return; + LoadFile(filename.toUtf8().data()); +} + +void MainWin::FileOpenRecent(void) +{ + QAction * action = qobject_cast(sender()); + + if (!action) + return; + + LoadFile(action->data().toString()); +} + +void MainWin::LoadFile(QString filename) +{ MapView * map = new MapView; bool successful = ReadFile(map->doc, filename.toUtf8().data()); @@ -151,6 +161,7 @@ void MainWin::FileOpen(void) msg.setText(QString(tr("Could not load file \"%1\"!")).arg(filename)); msg.setIcon(QMessageBox::Critical); msg.exec(); + return; } @@ -164,10 +175,10 @@ void MainWin::FileOpen(void) connect(map, SIGNAL(RoomClicked(MapDoc *, int)), rw, SLOT(ShowInfo(MapDoc *, int))); + AdjustMRU(filename); statusBar()->showMessage(tr("Map loaded."), 2000); } - void MainWin::FileSaveBase(MapView * map, QString filename) { if (filename.endsWith(".gmp") == false) @@ -193,7 +204,6 @@ void MainWin::FileSaveBase(MapView * map, QString filename) statusBar()->showMessage(tr("Map saved."), 2000); } - void MainWin::FileSave(void) { QMdiSubWindow * sw = mdiArea.activeSubWindow(); @@ -213,7 +223,6 @@ void MainWin::FileSave(void) FileSaveBase(map, filename); } - void MainWin::FileSaveAs(void) { QMdiSubWindow * sw = mdiArea.activeSubWindow(); @@ -230,7 +239,6 @@ void MainWin::FileSaveAs(void) FileSaveBase(map, filename); } - void MainWin::FileClose(void) { QMdiSubWindow * sw = mdiArea.activeSubWindow(); @@ -255,7 +263,6 @@ void MainWin::FileClose(void) statusBar()->showMessage(tr("Map closed."), 2000); } - void MainWin::EditUndo(void) { QMdiSubWindow * sw = mdiArea.activeSubWindow(); @@ -279,7 +286,6 @@ void MainWin::EditUndo(void) statusBar()->showMessage(tr("Ready.")); } - void MainWin::MenuFixUndo(void) { QMdiSubWindow * sw = mdiArea.activeSubWindow(); @@ -302,7 +308,6 @@ void MainWin::MenuFixUndo(void) } } - void MainWin::EditDelete(void) { QMdiSubWindow * sw = mdiArea.activeSubWindow(); @@ -319,7 +324,6 @@ void MainWin::EditDelete(void) map->update(); } - void MainWin::EditSelectAll(void) { QMdiSubWindow * sw = mdiArea.activeSubWindow(); @@ -338,13 +342,11 @@ void MainWin::EditSelectAll(void) map->update(); } - void MainWin::HelpAbout(void) { aboutWin->show(); } - void MainWin::CreateActions(void) { fileNewAct = CreateAction(tr("&New Map"), tr("New Map"), tr("Creates a new map."), QIcon(":/res/file-new.png"), QKeySequence(tr("Ctrl+n"))); @@ -377,77 +379,28 @@ void MainWin::CreateActions(void) aboutAct = CreateAction(tr("About &GUEmap"), tr("About GUEmap"), tr("Gives information about this program."), QIcon(), QKeySequence()); connect(aboutAct, SIGNAL(triggered()), this, SLOT(HelpAbout())); -#if 0 - snapToGridAct = CreateAction(tr("Snap To &Grid"), tr("Snap To Grid"), tr("Snaps mouse cursor to the visible grid when moving/creating objects."), QIcon(":/res/snap-to-grid-tool.png"), QKeySequence(tr("S")), true); - connect(snapToGridAct, SIGNAL(triggered()), this, SLOT(SnapToGridTool())); - - fixAngleAct = CreateAction(tr("Fix &Angle"), tr("Fix Angle"), tr("Fixes the angle of an object."), - QIcon(":/res/fix-angle.png"), QKeySequence(tr("F,A")), true); - connect(fixAngleAct, SIGNAL(triggered()), this, SLOT(FixAngle())); - - fixLengthAct = CreateAction(tr("Fix &Length"), tr("Fix Length"), tr("Fixes the length of an object."), - QIcon(":/res/fix-length.png"), QKeySequence(tr("F,L")), true); - connect(fixLengthAct, SIGNAL(triggered()), this, SLOT(FixLength())); - - deleteAct = CreateAction(tr("&Delete"), tr("Delete Object"), tr("Deletes selected objects."), QIcon(":/res/delete-tool.png"), QKeySequence(tr("Delete")), true); - connect(deleteAct, SIGNAL(triggered()), this, SLOT(DeleteTool())); - - addDimensionAct = CreateAction(tr("Add &Dimension"), tr("Add Dimension"), tr("Adds a dimension to the drawing."), QIcon(":/res/dimension-tool.png"), QKeySequence("D,I"), true); - connect(addDimensionAct, SIGNAL(triggered()), this, SLOT(DimensionTool())); - - addLineAct = CreateAction(tr("Add &Line"), tr("Add Line"), tr("Adds lines to the drawing."), QIcon(":/res/add-line-tool.png"), QKeySequence("A,L"), true); - connect(addLineAct, SIGNAL(triggered()), this, SLOT(AddLineTool())); - - addCircleAct = CreateAction(tr("Add &Circle"), tr("Add Circle"), tr("Adds circles to the drawing."), QIcon(":/res/add-circle-tool.png"), QKeySequence("A,C"), true); - connect(addCircleAct, SIGNAL(triggered()), this, SLOT(AddCircleTool())); - - addArcAct = CreateAction(tr("Add &Arc"), tr("Add Arc"), tr("Adds arcs to the drawing."), QIcon(":/res/add-arc-tool.png"), QKeySequence("A,A"), true); - connect(addArcAct, SIGNAL(triggered()), this, SLOT(AddArcTool())); - - addPolygonAct = CreateAction(tr("Add &Polygon"), tr("Add Polygon"), tr("Add polygons to the drawing."), QIcon(":/res/add-polygon-tool.png"), QKeySequence("A,P"), true); - connect(addPolygonAct, SIGNAL(triggered()), this, SLOT(AddPolygonTool())); - - addSplineAct = CreateAction(tr("Add &Spline"), tr("Add Spline"), tr("Add a NURB spline to the drawing."), QIcon(":/res/add-spline-tool.png"), QKeySequence("A,S"), true); - connect(addSplineAct, SIGNAL(triggered()), this, SLOT(AddSplineTool())); - - rotateAct = CreateAction(tr("&Rotate Objects"), tr("Rotate"), tr("Rotate object(s) around an arbitrary center."), QIcon(":/res/rotate-tool.png"), QKeySequence(tr("R,O")), true); - connect(rotateAct, SIGNAL(triggered()), this, SLOT(RotateTool())); - - zoomInAct = CreateAction(tr("Zoom &In"), tr("Zoom In"), tr("Zoom in on the document."), QIcon(":/res/zoom-in.png"), QKeySequence(tr("+")), QKeySequence(tr("="))); - connect(zoomInAct, SIGNAL(triggered()), this, SLOT(ZoomInTool())); - - zoomOutAct = CreateAction(tr("Zoom &Out"), tr("Zoom Out"), tr("Zoom out of the document."), QIcon(":/res/zoom-out.png"), QKeySequence(tr("-"))); - connect(zoomOutAct, SIGNAL(triggered()), this, SLOT(ZoomOutTool())); - - settingsAct = CreateAction(tr("&Settings"), tr("Settings"), tr("Change certain defaults for Architektonas."), QIcon(":/res/settings.png"), QKeySequence()); - connect(settingsAct, SIGNAL(triggered()), this, SLOT(Settings())); - - groupAct = CreateAction(tr("&Group"), tr("Group"), tr("Group/ungroup selected objects."), QIcon(":/res/group-tool.png"), QKeySequence("g")); - connect(groupAct, SIGNAL(triggered()), this, SLOT(HandleGrouping())); - - connectAct = CreateAction(tr("&Connect"), tr("Connect"), tr("Connect objects at point."), QIcon(":/res/connect-tool.png"), QKeySequence("c,c")); - connect(connectAct, SIGNAL(triggered()), this, SLOT(HandleConnection())); - - disconnectAct = CreateAction(tr("&Disconnect"), tr("Disconnect"), tr("Disconnect objects joined at point."), QIcon(":/res/disconnect-tool.png"), QKeySequence("d,d")); - connect(disconnectAct, SIGNAL(triggered()), this, SLOT(HandleDisconnection())); - - mirrorAct = CreateAction(tr("&Mirror"), tr("Mirror"), tr("Mirror selected objects around a line."), QIcon(":/res/mirror-tool.png"), QKeySequence("m,i"), true); - connect(mirrorAct, SIGNAL(triggered()), this, SLOT(MirrorTool())); - - trimAct = CreateAction(tr("&Trim"), tr("Trim"), tr("Trim extraneous lines from selected objects."), QIcon(":/res/trim-tool.png"), QKeySequence("t,r"), true); - connect(trimAct, SIGNAL(triggered()), this, SLOT(TrimTool())); - - triangulateAct = CreateAction(tr("&Triangulate"), tr("Triangulate"), tr("Make triangles from selected lines, preserving their lengths."), QIcon(":/res/triangulate-tool.png"), QKeySequence("t,g"), true); - connect(triangulateAct, SIGNAL(triggered()), this, SLOT(TriangulateTool())); -#endif + for(int i=0; isetVisible(false); + connect(rfa, SIGNAL(triggered()), this, SLOT(FileOpenRecent())); + mruAct.append(rfa); + } } - void MainWin::CreateMenus(void) { QMenu * menu = menuBar()->addMenu(tr("&File")); menu->addAction(fileNewAct); menu->addAction(fileOpenAct); + + QMenu * recentMenu = menu->addMenu(tr("Open &Recent")); + + for(int i=0; iaddAction(mruAct.at(i)); + + UpdateMRUActionList(); + menu->addAction(fileSaveAct); menu->addAction(fileSaveAsAct); menu->addAction(fileCloseAct); @@ -491,7 +444,6 @@ void MainWin::CreateMenus(void) menu->addAction(aboutAct); } - void MainWin::CreateToolbars(void) { #if 0 @@ -554,7 +506,6 @@ void MainWin::CreateToolbars(void) #endif } - void MainWin::ReadSettings(void) { QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint(); @@ -566,7 +517,6 @@ void MainWin::ReadSettings(void) restoreState(settings.value("windowState").toByteArray()); } - void MainWin::WriteSettings(void) { settings.setValue("pos", pos()); @@ -576,6 +526,40 @@ void MainWin::WriteSettings(void) // settings.setValue("snapToGrid", snapToGridAct->isChecked()); } +void MainWin::UpdateMRUActionList(void) +{ + QStringList mruFilePaths = settings.value("recentFiles").toStringList(); + + int mruSize = (mruFilePaths.size() <= MRU_MAX ? mruFilePaths.size() : MRU_MAX); + + for(int i=0; isetText(filename); + mruAct.at(i)->setData(mruFilePaths.at(i)); + mruAct.at(i)->setVisible(true); + } + + for(int i=mruSize; isetVisible(false); +} + +void MainWin::AdjustMRU(const QString & filePath) +{ + documentName = filePath; + setWindowFilePath(documentName); + + QStringList mruFilePaths = settings.value("recentFiles").toStringList(); + mruFilePaths.removeAll(filePath); + mruFilePaths.prepend(filePath); + + while (mruFilePaths.size() > MRU_MAX) + mruFilePaths.removeLast(); + + settings.setValue("recentFiles", mruFilePaths); + + UpdateMRUActionList(); +} #if 0 int MainWin::OnCreate(LPCREATESTRUCT lpCreateStruct) @@ -689,4 +673,3 @@ void MainWin::DockControlBarLeftOf(CControlBar * Bar, CControlBar * LeftOf) DockControlBar(Bar, n, &rect); } #endif - diff --git a/src/mainwin.h b/src/mainwin.h index f2b05df..bcb30d2 100644 --- a/src/mainwin.h +++ b/src/mainwin.h @@ -14,6 +14,10 @@ #include +// Useful definitions + +#define MRU_MAX 10 + class AboutWindow; class MapView; class RoomWidget; @@ -33,6 +37,7 @@ class MainWin: public QMainWindow protected slots: void FileNew(void); void FileOpen(void); + void FileOpenRecent(void); void FileSaveBase(MapView *, QString); void FileSave(void); void FileSaveAs(void); @@ -44,11 +49,14 @@ class MainWin: public QMainWindow void HelpAbout(void); private: + void LoadFile(QString); void CreateActions(void); void CreateMenus(void); void CreateToolbars(void); void ReadSettings(void); void WriteSettings(void); + void UpdateMRUActionList(void); + void AdjustMRU(const QString & filePath); public: // CDialogBar wndNavBar; @@ -56,6 +64,7 @@ class MainWin: public QMainWindow QSettings settings; AboutWindow * aboutWin; RoomWidget * rw; + QString documentName; private: QAction * fileNewAct; @@ -69,6 +78,7 @@ class MainWin: public QMainWindow QAction * selectAllAct; QAction * aboutAct; // QAction * Act; + QList mruAct; #if 0 public: // void setStatusBar(LPCTSTR text) {m_wndStatusBar.SetWindowText(text);}; diff --git a/src/mapview.cpp b/src/mapview.cpp index 7a915ed..6e1199f 100644 --- a/src/mapview.cpp +++ b/src/mapview.cpp @@ -424,6 +424,16 @@ void MapView::paintEvent(QPaintEvent * /*event*/) { roomWidth / 4 - 48, roomHeight + 52 } }; + // Offsets used when the label collides with the line... + const QPoint edgLblOffsetEx[] = { + // N, S, E, W + { -48, 0 }, { 48, 0 }, { 0, -76 }, { 0, 76 }, + // NE, NW, SE, SW + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, + // NNE, NNW, SSE, SSW + { -48, 0 }, { -48, 0 }, { 48, 0 }, { 48, 0 } + }; + const int cantGoSide = 19, cantGoAngleX = gridY / 6, @@ -723,18 +733,46 @@ printf(" clip = %i, %i, %i, %i; docSize = %i, %i\n", clip.left(), clip.right( if (edge->type1 & etDirection) { + QPoint ex = QPoint(0, 0); + double angle = Angle(end - start); + + if (angle < 0) + angle += TAU; + + // Adjust text position if it runs into an edge + if (((edge->end1 == rcNNW || edge->end1 == rcN || edge->end1 == rcNNE) && (angle > THREE_QTR_TAU && angle < TAU)) + || ((edge->end1 == rcSSW || edge->end1 == rcS || edge->end1 == rcSSE) && (angle > QTR_TAU && angle < HALF_TAU)) + || ((edge->end1 == rcE) && (angle > 0 && angle < QTR_TAU)) + || ((edge->end1 == rcW) && (angle > HALF_TAU && angle < THREE_QTR_TAU))) + { + ex = edgLblOffsetEx[edge->end1]; + } + const QPoint & p = room[edge->room1]->pos; -// dc->TextOut(p.x + edgLblXOffset[edge->end1], p.y + edgLblYOffset[edge->end1], &edgeLabel[(edge->type1 & etDirection) - 1], 1); elBuf[0] = edgeLabel[(edge->type1 & etDirection) - 1]; - dc->drawText(p + edgLblOffset[edge->end1], elBuf); + dc->drawText(p + edgLblOffset[edge->end1] + ex, elBuf); } if (edge->type2 & etDirection) { + QPoint ex = QPoint(0, 0); + double angle = Angle(start - end); + + if (angle < 0) + angle += TAU; + + // Adjust text position if it runs into an edge + if (((edge->end2 == rcNNW || edge->end2 == rcN || edge->end2 == rcNNE) && (angle > THREE_QTR_TAU && angle < TAU)) + || ((edge->end2 == rcSSW || edge->end2 == rcS || edge->end2 == rcSSE) && (angle > QTR_TAU && angle < HALF_TAU)) + || ((edge->end2 == rcE) && (angle > 0 && angle < QTR_TAU)) + || ((edge->end2 == rcW) && (angle > HALF_TAU && angle < THREE_QTR_TAU))) + { + ex = edgLblOffsetEx[edge->end2]; + } + const QPoint & p = room[edge->room2]->pos; -// dc->TextOut(p.x + edgLblXOffset[edge->end2], p.y + edgLblYOffset[edge->end2], &edgeLabel[(edge->type2 & etDirection) - 1], 1); elBuf[0] = edgeLabel[(edge->type2 & etDirection) - 1]; - dc->drawText(p + edgLblOffset[edge->end2], elBuf); + dc->drawText(p + edgLblOffset[edge->end2] + ex, elBuf); } edge--; -- 2.37.2
GUEmap: Free, IF Mapping Software
Version: 3.0.0
Version: 3.0.1
License: GPL v2 or later
Chief Architect: James Hammons (shamus)
Coders: James Hammons (shamus)
Christopher J. Madsen