summaryrefslogtreecommitdiff
path: root/src/gui/windows/mailwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/windows/mailwindow.cpp')
-rw-r--r--src/gui/windows/mailwindow.cpp61
1 files changed, 44 insertions, 17 deletions
diff --git a/src/gui/windows/mailwindow.cpp b/src/gui/windows/mailwindow.cpp
index 4f5f9cac5..cd3c8c6cf 100644
--- a/src/gui/windows/mailwindow.cpp
+++ b/src/gui/windows/mailwindow.cpp
@@ -92,25 +92,38 @@ MailWindow::MailWindow() :
if (setupWindow != nullptr)
setupWindow->registerWindowForReset(this);
- setDefaultSize(310, 180, ImagePosition::CENTER, 0, 0);
- setMinWidth(310);
- setMinHeight(250);
- center();
-
+ // use line wrapping of mail subjects, instead.
mListScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
-
- ContainerPlacer placer(nullptr, nullptr);
- placer = getPlacer(0, 0);
-
- placer(0, 0, mListScrollArea, 4, 5).setPadding(3);
- placer(4, 0, mRefreshButton, 1, 1);
- placer(4, 1, mOpenButton, 1, 1);
- placer(4, 2, mNewButton, 1, 1);
- placer(4, 3, mDeleteButton, 1, 1);
- placer(4, 4, mReturnButton, 1, 1);
+ // set reasonable minimum width for calculations below
+ mListScrollArea->setWidth(200);
+
+ // at 0,0 and spawns/spans 4 columns and 6 rows
+ place(0, 0, mListScrollArea, 1, 6).setPadding(3);
+ // at column 5 and row 0...
+ place(1, 0, mRefreshButton, 1, 1);
+ place(1, 1, mOpenButton, 1, 1);
+ place(1, 2, mNewButton, 1, 1);
+ // Leave intentional gap in grid so that the button column (and thus,
+ // the whole window) can be resized without resizing any of the buttons.
+ // note: the empty cell still seems to enforce some padding, but this
+ // is fine.
+ place(1, 4, mDeleteButton, 1, 1);
+ place(1, 5, mReturnButton, 1, 1);
Layout &layout = getLayout();
- layout.setRowHeight(0, LayoutType::SET);
+ // scrollarea column and 4th row eat all remaining available screen space.
+ layout.setColWidth(0, LayoutType::SET);
+ layout.setRowHeight(3, LayoutType::SET);
+
+ // Enforce a minimum size.
+ int width = 0;
+ int height = 0;
+ layout.reflow(width, height);
+ setContentSize(width, height);
+ setMinWidth(getWidth());
+ setMinHeight(getHeight());
+ setDefaultSize(getWidth(), getHeight(), ImagePosition::CENTER, 0, 0);
+ center();
loadWindowState();
enableVisibleSound(true);
@@ -244,7 +257,14 @@ void MailWindow::removeMail(const int64_t id)
if ((message != nullptr) && message->id == id)
{
mMessages.erase(it);
- delete message;
+ // passes ownership of message pointer to mailViewWindow,
+ // which will signal to reader that the mail is deleted and
+ // will do the final delete of the message upon destruction.
+ if (mailViewWindow == nullptr ||
+ !mailViewWindow->notifyDeleteAndTransferOwnership(id))
+ {
+ delete message;
+ }
break;
}
}
@@ -255,6 +275,13 @@ void MailWindow::removeMail(const int64_t id)
if (message != nullptr)
mMailModel->add(getMailHeader(message));
}
+
+ // if player deleted the selected mail, then selection does not change
+ // (selects next one in list). However, if they deleted the last one,
+ // then we go to the previous one in list.
+ const auto lastIndex = mMailModel->getNumberOfElements() - 1;
+ if (mListBox->getSelected() > lastIndex)
+ mListBox->setSelected(lastIndex);
}
void MailWindow::showMessage(MailMessage *const mail,