mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-24 23:36:01 -05:00
Merge a601a99817 into b4a5c863d7
This commit is contained in:
commit
320cdb8ccb
|
|
@ -181,6 +181,8 @@ set(cockatrice_SOURCES
|
|||
src/interface/widgets/deck_editor/deck_list_style_proxy.cpp
|
||||
src/interface/widgets/deck_editor/deck_state_manager.cpp
|
||||
src/interface/widgets/deck_editor/printing_disabled_info_widget.cpp
|
||||
src/interface/widgets/game/journal_widget.cpp
|
||||
src/interface/widgets/game/journal_widget.h
|
||||
src/interface/widgets/general/background_sources.cpp
|
||||
src/interface/widgets/general/display/background_plate_widget.cpp
|
||||
src/interface/widgets/general/display/banner_widget.cpp
|
||||
|
|
|
|||
104
cockatrice/src/interface/widgets/game/journal_widget.cpp
Normal file
104
cockatrice/src/interface/widgets/game/journal_widget.cpp
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
#include "journal_widget.h"
|
||||
|
||||
#include "../../../client/settings/cache_settings.h"
|
||||
|
||||
#include <QLayout>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QPushButton>
|
||||
|
||||
static const QString BACKUP_FILE_NAME = "journal.txt";
|
||||
|
||||
JournalRestoreWidget::JournalRestoreWidget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
auto layout = new QVBoxLayout(this);
|
||||
layout->setSpacing(3);
|
||||
layout->setAlignment(Qt::AlignCenter);
|
||||
setLayout(layout);
|
||||
|
||||
textLabel = new QLabel(this);
|
||||
restoreButton = new QPushButton(this);
|
||||
discardButton = new QPushButton(this);
|
||||
|
||||
layout->addWidget(textLabel);
|
||||
layout->addWidget(restoreButton);
|
||||
layout->addWidget(discardButton);
|
||||
|
||||
connect(restoreButton, &QPushButton::clicked, this, &JournalRestoreWidget::restorePushed);
|
||||
connect(discardButton, &QPushButton::clicked, this, &JournalRestoreWidget::discardPushed);
|
||||
|
||||
connect(&SettingsCache::instance(), &SettingsCache::langChanged, this, &JournalRestoreWidget::retranslateUi);
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void JournalRestoreWidget::retranslateUi()
|
||||
{
|
||||
textLabel->setText(tr("Previous journal text detected."));
|
||||
restoreButton->setText(tr("Restore"));
|
||||
discardButton->setText(tr("Discard"));
|
||||
}
|
||||
|
||||
static QString getJournalBackupPath()
|
||||
{
|
||||
return SettingsCache::instance().getDataPath() + "/" + BACKUP_FILE_NAME;
|
||||
}
|
||||
|
||||
static bool hasSavedBackupText()
|
||||
{
|
||||
QFileInfo fileInfo = QFileInfo(getJournalBackupPath());
|
||||
return fileInfo.size() != 0;
|
||||
}
|
||||
|
||||
JournalWidget::JournalWidget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
auto layout = new QHBoxLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
setLayout(layout);
|
||||
|
||||
textEdit = new QPlainTextEdit(this);
|
||||
restoreWidget = new JournalRestoreWidget(this);
|
||||
|
||||
layout->addWidget(textEdit);
|
||||
layout->addWidget(restoreWidget);
|
||||
|
||||
showRestorePrompt(hasSavedBackupText());
|
||||
|
||||
connect(restoreWidget, &JournalRestoreWidget::discardPushed, this, [this] { showRestorePrompt(false); });
|
||||
connect(restoreWidget, &JournalRestoreWidget::restorePushed, this, [this] {
|
||||
restoreText();
|
||||
showRestorePrompt(false);
|
||||
});
|
||||
|
||||
// Debounce setup
|
||||
debounceTimer.setSingleShot(true);
|
||||
connect(&debounceTimer, &QTimer::timeout, this, &JournalWidget::backupText);
|
||||
connect(textEdit, &QPlainTextEdit::textChanged, this, [this] { debounceTimer.start(300); });
|
||||
}
|
||||
|
||||
void JournalWidget::showRestorePrompt(bool show)
|
||||
{
|
||||
restoreWidget->setVisible(show);
|
||||
textEdit->setVisible(!show);
|
||||
}
|
||||
|
||||
void JournalWidget::backupText()
|
||||
{
|
||||
QFile file(getJournalBackupPath());
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString text = textEdit->toPlainText();
|
||||
file.write(text.toUtf8());
|
||||
}
|
||||
|
||||
void JournalWidget::restoreText()
|
||||
{
|
||||
QFile file(getJournalBackupPath());
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray byteArray = file.readAll();
|
||||
textEdit->setPlainText(QString::fromUtf8(byteArray));
|
||||
}
|
||||
51
cockatrice/src/interface/widgets/game/journal_widget.h
Normal file
51
cockatrice/src/interface/widgets/game/journal_widget.h
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#ifndef COCKATRICE_JOURNAL_WIDGET_H
|
||||
#define COCKATRICE_JOURNAL_WIDGET_H
|
||||
#include <QFileInfo>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QTimer>
|
||||
#include <QWidget>
|
||||
#include <qplaintextedit.h>
|
||||
|
||||
/**
|
||||
* The widget that is used to show the journal restore prompt.
|
||||
*/
|
||||
class JournalRestoreWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QLabel *textLabel;
|
||||
QPushButton *restoreButton;
|
||||
QPushButton *discardButton;
|
||||
|
||||
public:
|
||||
explicit JournalRestoreWidget(QWidget *parent = nullptr);
|
||||
|
||||
void retranslateUi();
|
||||
|
||||
signals:
|
||||
void restorePushed();
|
||||
void discardPushed();
|
||||
};
|
||||
|
||||
/**
|
||||
* The widget used in the Journal dock in the game tab.
|
||||
*/
|
||||
class JournalWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QPlainTextEdit *textEdit;
|
||||
JournalRestoreWidget *restoreWidget;
|
||||
QTimer debounceTimer;
|
||||
|
||||
public:
|
||||
explicit JournalWidget(QWidget *parent = nullptr);
|
||||
|
||||
private slots:
|
||||
void showRestorePrompt(bool show);
|
||||
void backupText();
|
||||
void restoreText();
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_JOURNAL_WIDGET_H
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
#include "../interface/card_picture_loader/card_picture_loader.h"
|
||||
#include "../interface/widgets/cards/card_info_frame_widget.h"
|
||||
#include "../interface/widgets/dialogs/dlg_create_game.h"
|
||||
#include "../interface/widgets/game/journal_widget.h"
|
||||
#include "../interface/widgets/server/user/user_list_manager.h"
|
||||
#include "../interface/widgets/utility/line_edit_completer.h"
|
||||
#include "../interface/window_main.h"
|
||||
|
|
@ -31,6 +32,7 @@
|
|||
#include <QLabel>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QStackedWidget>
|
||||
#include <QTimer>
|
||||
#include <QWidget>
|
||||
|
|
@ -51,6 +53,7 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, GameReplay *_replay)
|
|||
|
||||
createCardInfoDock(true);
|
||||
createPlayerListDock(true);
|
||||
createJournalDock(true);
|
||||
createMessageDock(true);
|
||||
createPlayAreaWidget(true);
|
||||
createDeckViewContainerWidget(true);
|
||||
|
|
@ -58,6 +61,7 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, GameReplay *_replay)
|
|||
|
||||
addDockWidget(Qt::RightDockWidgetArea, cardInfoDock);
|
||||
addDockWidget(Qt::RightDockWidgetArea, playerListDock);
|
||||
addDockWidget(Qt::RightDockWidgetArea, journalDock);
|
||||
addDockWidget(Qt::RightDockWidgetArea, messageLayoutDock);
|
||||
addDockWidget(Qt::BottomDockWidgetArea, replayDock);
|
||||
|
||||
|
|
@ -95,6 +99,7 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor,
|
|||
|
||||
createCardInfoDock();
|
||||
createPlayerListDock();
|
||||
createJournalDock();
|
||||
createMessageDock();
|
||||
createPlayAreaWidget();
|
||||
createDeckViewContainerWidget();
|
||||
|
|
@ -102,6 +107,7 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor,
|
|||
|
||||
addDockWidget(Qt::RightDockWidgetArea, cardInfoDock);
|
||||
addDockWidget(Qt::RightDockWidgetArea, playerListDock);
|
||||
addDockWidget(Qt::RightDockWidgetArea, journalDock);
|
||||
addDockWidget(Qt::RightDockWidgetArea, messageLayoutDock);
|
||||
|
||||
mainWidget = new QStackedWidget(this);
|
||||
|
|
@ -278,6 +284,7 @@ void TabGame::retranslateUi()
|
|||
|
||||
updatePlayerListDockTitle();
|
||||
cardInfoDock->setWindowTitle(tr("Card Info") + (cardInfoDock->isWindow() ? tabText : QString()));
|
||||
journalDock->setWindowTitle(tr("Journal") + (journalDock->isWindow() ? tabText : QString()));
|
||||
messageLayoutDock->setWindowTitle(tr("Messages") + (messageLayoutDock->isWindow() ? tabText : QString()));
|
||||
if (replayDock)
|
||||
replayDock->setWindowTitle(tr("Replay Timeline") + (replayDock->isWindow() ? tabText : QString()));
|
||||
|
|
@ -341,6 +348,7 @@ void TabGame::retranslateUi()
|
|||
|
||||
dockToActions[cardInfoDock].menu->setTitle(tr("Card Info"));
|
||||
dockToActions[messageLayoutDock].menu->setTitle(tr("Messages"));
|
||||
dockToActions[journalDock].menu->setTitle(tr("Journal"));
|
||||
dockToActions[playerListDock].menu->setTitle(tr("Player List"));
|
||||
|
||||
if (replayDock) {
|
||||
|
|
@ -1035,6 +1043,7 @@ void TabGame::createViewMenuItems()
|
|||
registerDockWidget(viewMenu, cardInfoDock, {250, 360});
|
||||
registerDockWidget(viewMenu, messageLayoutDock, {250, 200});
|
||||
registerDockWidget(viewMenu, playerListDock, {250, 50});
|
||||
registerDockWidget(viewMenu, journalDock, {250, 50});
|
||||
|
||||
if (replayDock) {
|
||||
registerDockWidget(viewMenu, replayDock, {900, 100});
|
||||
|
|
@ -1124,36 +1133,31 @@ void TabGame::actResetLayout()
|
|||
{
|
||||
cardInfoDock->setVisible(true);
|
||||
playerListDock->setVisible(true);
|
||||
journalDock->setVisible(false);
|
||||
messageLayoutDock->setVisible(true);
|
||||
|
||||
cardInfoDock->setFloating(false);
|
||||
playerListDock->setFloating(false);
|
||||
journalDock->setFloating(false);
|
||||
messageLayoutDock->setFloating(false);
|
||||
|
||||
addDockWidget(Qt::RightDockWidgetArea, cardInfoDock);
|
||||
addDockWidget(Qt::RightDockWidgetArea, playerListDock);
|
||||
addDockWidget(Qt::RightDockWidgetArea, journalDock);
|
||||
addDockWidget(Qt::RightDockWidgetArea, messageLayoutDock);
|
||||
|
||||
if (replayDock) {
|
||||
replayDock->setVisible(true);
|
||||
replayDock->setFloating(false);
|
||||
addDockWidget(Qt::BottomDockWidgetArea, replayDock);
|
||||
}
|
||||
|
||||
cardInfoDock->setMinimumSize(250, 360);
|
||||
cardInfoDock->setMaximumSize(250, 360);
|
||||
messageLayoutDock->setMinimumSize(250, 200);
|
||||
messageLayoutDock->setMaximumSize(250, 200);
|
||||
playerListDock->setMinimumSize(250, 50);
|
||||
playerListDock->setMaximumSize(250, 50);
|
||||
replayDock->setMinimumSize(900, 100);
|
||||
replayDock->setMaximumSize(900, 100);
|
||||
} else {
|
||||
cardInfoDock->setMinimumSize(250, 360);
|
||||
cardInfoDock->setMaximumSize(250, 360);
|
||||
messageLayoutDock->setMinimumSize(250, 250);
|
||||
messageLayoutDock->setMaximumSize(250, 250);
|
||||
playerListDock->setMinimumSize(250, 50);
|
||||
playerListDock->setMaximumSize(250, 50);
|
||||
for (auto i = dockToActions.cbegin(); i != dockToActions.cend(); ++i) {
|
||||
QDockWidget *dock = i.key();
|
||||
QSize defaultSize = i.value().defaultSize;
|
||||
|
||||
dock->setMinimumSize(defaultSize);
|
||||
dock->setMaximumSize(defaultSize);
|
||||
}
|
||||
|
||||
QTimer::singleShot(100, this, &TabGame::freeDocksSize);
|
||||
|
|
@ -1248,6 +1252,22 @@ void TabGame::createPlayerListDock(bool bReplay)
|
|||
playerListDock->setFloating(false);
|
||||
}
|
||||
|
||||
void TabGame::createJournalDock(bool bReplay)
|
||||
{
|
||||
Q_UNUSED(bReplay);
|
||||
|
||||
journalWidget = new JournalWidget(this);
|
||||
|
||||
journalDock = new QDockWidget(this);
|
||||
journalDock->setObjectName("journalDock");
|
||||
journalDock->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable |
|
||||
QDockWidget::DockWidgetMovable);
|
||||
journalDock->setWidget(journalWidget);
|
||||
|
||||
// Prevent text from autofocusing if there are no other focusable widgets (such as when loading replay)
|
||||
QTimer::singleShot(1, journalWidget, &QWidget::clearFocus);
|
||||
}
|
||||
|
||||
void TabGame::createMessageDock(bool bReplay)
|
||||
{
|
||||
auto messageLogLayout = new QVBoxLayout;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
#include <QLoggingCategory>
|
||||
#include <QMap>
|
||||
|
||||
class JournalWidget;
|
||||
class ServerInfo_PlayerProperties;
|
||||
class TabbedDeckViewContainer;
|
||||
inline Q_LOGGING_CATEGORY(TabGameLog, "tab_game");
|
||||
|
|
@ -66,6 +67,7 @@ private:
|
|||
|
||||
CardInfoFrameWidget *cardInfoFrameWidget;
|
||||
PlayerListWidget *playerListWidget;
|
||||
JournalWidget *journalWidget;
|
||||
QLabel *timeElapsedLabel;
|
||||
MessageLogWidget *messageLog;
|
||||
QLabel *sayLabel;
|
||||
|
|
@ -76,7 +78,7 @@ private:
|
|||
QMap<int, TabbedDeckViewContainer *> deckViewContainers;
|
||||
QVBoxLayout *deckViewContainerLayout;
|
||||
QWidget *gamePlayAreaWidget, *deckViewContainerWidget;
|
||||
QDockWidget *cardInfoDock, *messageLayoutDock, *playerListDock, *replayDock;
|
||||
QDockWidget *cardInfoDock, *playerListDock, *journalDock, *messageLayoutDock, *replayDock;
|
||||
QAction *playersSeparator;
|
||||
QMenu *gameMenu, *viewMenu;
|
||||
TearOffMenu *phasesMenu;
|
||||
|
|
@ -121,6 +123,7 @@ private:
|
|||
void registerDockWidget(QMenu *_viewMenu, QDockWidget *widget, const QSize &defaultSize);
|
||||
void createCardInfoDock(bool bReplay = false);
|
||||
void createPlayerListDock(bool bReplay = false);
|
||||
void createJournalDock(bool bReplay = false);
|
||||
void createMessageDock(bool bReplay = false);
|
||||
void createPlayAreaWidget(bool bReplay = false);
|
||||
void createDeckViewContainerWidget(bool bReplay = false);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user