Skip to content

Commit

Permalink
BugFix: close button on map custom exit dialog not cancelling line dr…
Browse files Browse the repository at this point in the history
…awing

As per http://bugs.launchpad.net/mudlet/+bug/1369041 the built-in dialog
button that some OS/Window systems provide did close the dialog but did not
cancel the custom line drawing process.  This fixes the matter by
connecting the reject() signal that the button produces to code to clean
up.

During debugging this it became clear that: if the custom line dialog was
being displayed but before the user had selected the exit to draw the line
for, it was possible to click on the map and add points to create a line;
this would be for a custom line with an Empty exit name which should not be
permitted.  To prevent this a flag "mDialogLock" was added to the class to
prevent the mouse events that would draw or modify a custom line from
proceeding until the custom line dialog had been used or cancelled.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
  • Loading branch information
SlySven committed Oct 13, 2014
1 parent b0e447d commit 07c6a3e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 15 deletions.
68 changes: 54 additions & 14 deletions src/T2DMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
T2DMap::T2DMap(QWidget * parent)
: QWidget(parent)
, mMultiSelectionListWidget(this)
, mDialogLock(false)
{
mMultiSelectionListWidget.setHeaderLabel("Room Selection");
mMultiSelectionListWidget.setColumnCount(1);
Expand Down Expand Up @@ -1832,6 +1833,8 @@ void T2DMap::paintEvent( QPaintEvent * e )

void T2DMap::mouseDoubleClickEvent ( QMouseEvent * event )
{
if( mDialogLock )
return;
int x = event->x();
int y = event->y();
mPHighlight = QPoint(x,y);
Expand Down Expand Up @@ -2018,6 +2021,9 @@ void T2DMap::mousePressEvent(QMouseEvent *event)
// drawing new custom exit line
if( mCustomLinesRoomFrom > 0 )
{
if( mDialogLock )
return; // Prevent any line drawing until ready

TRoom * pR = mpMap->mpRoomDB->getRoom( mCustomLinesRoomFrom );
if( pR )
{
Expand Down Expand Up @@ -2249,6 +2255,8 @@ void T2DMap::mousePressEvent(QMouseEvent *event)

if( mCustomLinesRoomFrom > 0 )
{
if( mDialogLock )
return;

TRoom * pR = mpMap->mpRoomDB->getRoom(mCustomLinesRoomFrom);
if( pR )
Expand Down Expand Up @@ -2526,6 +2534,10 @@ void T2DMap::slot_customLineProperties()

if( pR )
{
if( exit.isEmpty() ) {
qDebug("T2DMap::slot_customLineProperties() called but no exit is selected...");
return;
}
if( pR->customLines.contains( exit ) )
{
QUiLoader loader;
Expand Down Expand Up @@ -2743,7 +2755,7 @@ void T2DMap::slot_doneCustomLine()
{
if( mpCustomLinesDialog )
{
mpCustomLinesDialog->close(); // Have changed so that we don't close the dialog until finished drawing the line
mpCustomLinesDialog->accept();
mpCustomLinesDialog = 0;
}
mHelpMsg = "";
Expand Down Expand Up @@ -3619,6 +3631,12 @@ void T2DMap::slot_setCustomLine()
return;
if( ! mpHost->mpMap->mpRoomDB->getRoom( mMultiSelectionList[0] ) )
return;
if( mpCustomLinesDialog ) {
// Refuse to create another instance if one is already present!
// Just show it...
mpCustomLinesDialog->raise();
return;
}
QUiLoader loader;

QFile file(":/ui/custom_lines.ui");
Expand All @@ -3627,8 +3645,7 @@ void T2DMap::slot_setCustomLine()
file.close();
if( ! d )
return;
mpCustomLinesDialog = d;
mpCustomLinesDialog->setWindowIcon( QIcon( QStringLiteral( ":/icons/mudlet_custom_exit.png" ) ) );
d->setWindowIcon( QIcon( QStringLiteral( ":/icons/mudlet_custom_exit.png" ) ) );
TRoom * pR = mpMap->mpRoomDB->getRoom(mMultiSelectionList[0]);
if( !pR )
return;
Expand Down Expand Up @@ -3886,8 +3903,8 @@ void T2DMap::slot_setCustomLine()
qWarning("T2DMap::slot_setCustomLine() ERROR: failed to find \"cancel\" button!");
return;
}
connect(b_, SIGNAL(clicked()), this, SLOT(slot_setCustomLine2()));
// Arrange that even a cancel request gets handled by the slot_setCustomLine2() method
connect(b_, SIGNAL(clicked()), d, SLOT(reject()));
connect(d, SIGNAL(rejected()), this, SLOT(slot_cancelCustomLineDialog()));

QStringList _lineStyles;
_lineStyles << "solid line" << "dot line" << "dash line" << "dash dot line" << "dash dot dot line";
Expand All @@ -3897,8 +3914,10 @@ void T2DMap::slot_setCustomLine()
mpCurrentLineColor->setStyleSheet("background-color:" + mCurrentLineColor.name());
connect(specialExits, SIGNAL(itemClicked(QTreeWidgetItem *,int)), this, SLOT(slot_setCustomLine2B(QTreeWidgetItem*, int)));
connect(mpCurrentLineColor, SIGNAL(clicked()), this, SLOT(slot_customLineColor()));
d->show();
d->raise();
mpCustomLinesDialog = d; // Don't assign the pointer value to the class memeber until ready to go
mpCustomLinesDialog->show();
mpCustomLinesDialog->raise();
mDialogLock = true; // Prevent any line drawing until dialog has been used
}

void T2DMap::slot_customLineColor()
Expand All @@ -3917,20 +3936,40 @@ void T2DMap::slot_customLineColor()
}
}

// Called by dialog's reject event which is caused at least by "X" button on
// title bar and by ESC keypress...
void T2DMap::slot_cancelCustomLineDialog()
{
mpCustomLinesDialog->deleteLater();
mpCustomLinesDialog = 0;
mCustomLinesRoomFrom = 0;
mCustomLinesRoomTo = 0;
mCustomLinesRoomExit.clear();
mDialogLock = false;
}

void T2DMap::slot_setCustomLine2()
{
QPushButton* pB = qobject_cast<QPushButton *>( sender() );
if( ! pB || pB->objectName() == "button_cancel" )
if( ! pB )
{
mpCustomLinesDialog->close();
mCustomLinesRoomFrom = 0; // This is needed to escape from custom line exit drawing mode
mCustomLinesRoomTo = 0;
mCustomLinesRoomExit.clear();
if( mpCustomLinesDialog ) {
mpCustomLinesDialog->reject();
}
else {
// This is needed to escape from custom line exit drawing mode if
// the dialog has disappeared, not likely I think/hope
mCustomLinesRoomFrom = 0;
mCustomLinesRoomTo = 0;
mCustomLinesRoomExit.clear();
mDialogLock = false;
}
return;
}
QString exit = pB->text();
mpCustomLinesDialog->close();
mpCustomLinesDialog->hide(); // Hide but don't delete until done the custom line
mCustomLinesRoomExit = exit;
mDialogLock = false;
TRoom * pR = mpMap->mpRoomDB->getRoom(mCustomLinesRoomFrom);
if( ! pR )
return;
Expand Down Expand Up @@ -3991,9 +4030,10 @@ void T2DMap::slot_setCustomLine2B(QTreeWidgetItem * special_exit, int column )
if( ! special_exit )
return;
QString exit = special_exit->text(2);
mpCustomLinesDialog->close();
mpCustomLinesDialog->hide(); // Hide but don't delete until done the custom line
mCustomLinesRoomExit = exit;
mCustomLinesRoomTo = special_exit->text(1).toInt(); // Wasn't being set !
mDialogLock = false;
TRoom * pR = mpMap->mpRoomDB->getRoom(mCustomLinesRoomFrom);
if( ! pR )
return;
Expand Down
6 changes: 5 additions & 1 deletion src/T2DMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class T2DMap : public QWidget
bool mShiftMode;
bool mShowInfo;
QComboBox * arealist_combobox;
QDialog * mpCustomLinesDialog;
QPointer<QDialog> mpCustomLinesDialog;
int mCustomLinesRoomFrom;
int mCustomLinesRoomTo;
QString mCustomLinesRoomExit;
Expand Down Expand Up @@ -177,6 +177,10 @@ public slots:
void slot_customLineProperties();
void slot_customLineAddPoint();
void slot_customLineRemovePoint();
void slot_cancelCustomLineDialog();

private:
bool mDialogLock;
};

#endif // MUDLET_T2DMAP_H

0 comments on commit 07c6a3e

Please sign in to comment.