diff --git a/cockatrice/src/client/tabs/tab_account.cpp b/cockatrice/src/client/tabs/tab_account.cpp index f50197721..78517a82d 100644 --- a/cockatrice/src/client/tabs/tab_account.cpp +++ b/cockatrice/src/client/tabs/tab_account.cpp @@ -16,7 +16,6 @@ #include "tab_supervisor.h" #include "trice_limits.h" -#include #include #include @@ -44,72 +43,74 @@ TabAccount::TabAccount(TabSupervisor *_tabSupervisor, AbstractClient *_client, c buddyListReceived(tabSupervisor->getUserListManager()->getBuddyList().values()); ignoreListReceived(tabSupervisor->getUserListManager()->getIgnoreList().values()); - PendingCommand *pend = client->prepareSessionCommand(Command_ListUsers()); + PendingCommand *pend = AbstractClient::prepareSessionCommand(Command_ListUsers()); connect(pend, &PendingCommand::finished, this, &TabAccount::processListUsersResponse); client->sendCommand(pend); - QVBoxLayout *vbox = new QVBoxLayout; + auto *vbox = new QVBoxLayout; vbox->addWidget(userInfoBox); vbox->addWidget(allUsersList); - QHBoxLayout *addToBuddyList = new QHBoxLayout; + auto *addToBuddyList = new QHBoxLayout; addBuddyEdit = new LineEditUnfocusable; addBuddyEdit->setMaxLength(MAX_NAME_LENGTH); addBuddyEdit->setPlaceholderText(tr("Add to Buddy List")); connect(addBuddyEdit, &LineEditUnfocusable::returnPressed, this, &TabAccount::addToBuddyList); - QPushButton *addBuddyButton = new QPushButton("Add"); + auto *addBuddyButton = new QPushButton("Add"); connect(addBuddyButton, &QPushButton::clicked, this, &TabAccount::addToBuddyList); addToBuddyList->addWidget(addBuddyEdit); addToBuddyList->addWidget(addBuddyButton); - QHBoxLayout *addToIgnoreList = new QHBoxLayout; + auto *addToIgnoreList = new QHBoxLayout; addIgnoreEdit = new LineEditUnfocusable; addIgnoreEdit->setMaxLength(MAX_NAME_LENGTH); addIgnoreEdit->setPlaceholderText(tr("Add to Ignore List")); connect(addIgnoreEdit, &LineEditUnfocusable::returnPressed, this, &TabAccount::addToIgnoreList); - QPushButton *addIgnoreButton = new QPushButton("Add"); + auto *addIgnoreButton = new QPushButton("Add"); connect(addIgnoreButton, &QPushButton::clicked, this, &TabAccount::addToIgnoreList); addToIgnoreList->addWidget(addIgnoreEdit); addToIgnoreList->addWidget(addIgnoreButton); - QVBoxLayout *buddyPanel = new QVBoxLayout; + auto *buddyPanel = new QVBoxLayout; buddyPanel->addWidget(buddyList); buddyPanel->addLayout(addToBuddyList); - QVBoxLayout *ignorePanel = new QVBoxLayout; + auto *ignorePanel = new QVBoxLayout; ignorePanel->addWidget(ignoreList); ignorePanel->addLayout(addToIgnoreList); - QHBoxLayout *mainLayout = new QHBoxLayout; + auto *mainLayout = new QHBoxLayout; mainLayout->addLayout(buddyPanel); mainLayout->addLayout(ignorePanel); mainLayout->addLayout(vbox); retranslateUi(); - QWidget *mainWidget = new QWidget(this); + auto *mainWidget = new QWidget(this); mainWidget->setLayout(mainLayout); setCentralWidget(mainWidget); } void TabAccount::addToBuddyList() { - QString userName = addBuddyEdit->text(); - if (userName.length() < 1) + const QString &userName = addBuddyEdit->text(); + if (userName.isEmpty()) { return; + } - std::string listName = "buddy"; + const std::string listName = "buddy"; addToList(listName, userName); addBuddyEdit->clear(); } void TabAccount::addToIgnoreList() { - QString userName = addIgnoreEdit->text(); - if (userName.length() < 1) + const QString &userName = addIgnoreEdit->text(); + if (userName.isEmpty()) { return; + } - std::string listName = "ignore"; + const std::string listName = "ignore"; addToList(listName, userName); addIgnoreEdit->clear(); } @@ -120,7 +121,7 @@ void TabAccount::addToList(const std::string &listName, const QString &userName) cmd.set_list(listName); cmd.set_user_name(userName.toStdString()); - client->sendCommand(client->prepareSessionCommand(cmd)); + client->sendCommand(AbstractClient::prepareSessionCommand(cmd)); } void TabAccount::retranslateUi() @@ -134,11 +135,9 @@ void TabAccount::retranslateUi() void TabAccount::processListUsersResponse(const Response &response) { const Response_ListUsers &resp = response.GetExtension(Response_ListUsers::ext); - - const int userListSize = resp.user_list_size(); - for (int i = 0; i < userListSize; ++i) { + for (int i = 0; i < resp.user_list_size(); ++i) { const ServerInfo_User &info = resp.user_list(i); - const QString userName = QString::fromStdString(info.name()); + const QString &userName = QString::fromStdString(info.name()); allUsersList->processUserInfo(info, true); ignoreList->setUserOnline(userName, true); buddyList->setUserOnline(userName, true); @@ -152,7 +151,7 @@ void TabAccount::processListUsersResponse(const Response &response) void TabAccount::processUserJoinedEvent(const Event_UserJoined &event) { const ServerInfo_User &info = event.user_info(); - const QString userName = QString::fromStdString(info.name()); + const QString &userName = QString::fromStdString(info.name()); allUsersList->processUserInfo(info, true); ignoreList->setUserOnline(userName, true); @@ -162,18 +161,20 @@ void TabAccount::processUserJoinedEvent(const Event_UserJoined &event) ignoreList->sortItems(); buddyList->sortItems(); - if (buddyList->getUsers().keys().contains(userName)) + if (buddyList->getUsers().keys().contains(userName)) { soundEngine->playSound("buddy_join"); + } emit userJoined(info); } void TabAccount::processUserLeftEvent(const Event_UserLeft &event) { - QString userName = QString::fromStdString(event.name()); + const QString &userName = QString::fromStdString(event.name()); - if (buddyList->getUsers().keys().contains(userName)) + if (buddyList->getUsers().keys().contains(userName)) { soundEngine->playSound("buddy_leave"); + } if (allUsersList->deleteUser(userName)) { ignoreList->setUserOnline(userName, false); @@ -187,30 +188,34 @@ void TabAccount::processUserLeftEvent(const Event_UserLeft &event) void TabAccount::buddyListReceived(const QList &_buddyList) { - for (const auto &user : _buddyList) + for (const auto &user : _buddyList) { buddyList->processUserInfo(user, false); + } buddyList->sortItems(); } void TabAccount::ignoreListReceived(const QList &_ignoreList) { - for (const auto &user : _ignoreList) + for (const auto &user : _ignoreList) { ignoreList->processUserInfo(user, false); + } ignoreList->sortItems(); } void TabAccount::processAddToListEvent(const Event_AddToList &event) { const ServerInfo_User &info = event.user_info(); - bool online = allUsersList->getUsers().contains(QString::fromStdString(info.name())); - QString list = QString::fromStdString(event.list_name()); - UserListWidget *userList = 0; - if (list == "buddy") + const bool online = allUsersList->getUsers().contains(QString::fromStdString(info.name())); + const QString &list = QString::fromStdString(event.list_name()); + + UserListWidget *userList; + if (list == "buddy") { userList = buddyList; - else if (list == "ignore") + } else if (list == "ignore") { userList = ignoreList; - if (!userList) + } else { return; + } userList->processUserInfo(info, online); userList->sortItems(); @@ -218,14 +223,17 @@ void TabAccount::processAddToListEvent(const Event_AddToList &event) void TabAccount::processRemoveFromListEvent(const Event_RemoveFromList &event) { - QString list = QString::fromStdString(event.list_name()); - QString user = QString::fromStdString(event.user_name()); - UserListWidget *userList = 0; - if (list == "buddy") + const auto &list = QString::fromStdString(event.list_name()); + const auto &user = QString::fromStdString(event.user_name()); + + UserListWidget *userList; + if (list == "buddy") { userList = buddyList; - else if (list == "ignore") + } else if (list == "ignore") { userList = ignoreList; - if (!userList) + } else { return; + } + userList->deleteUser(user); } diff --git a/cockatrice/src/client/tabs/tab_account.h b/cockatrice/src/client/tabs/tab_account.h index 14a1cd189..5824a7527 100644 --- a/cockatrice/src/client/tabs/tab_account.h +++ b/cockatrice/src/client/tabs/tab_account.h @@ -5,17 +5,16 @@ #include "tab.h" class AbstractClient; -class UserListWidget; -class UserInfoBox; -class LineEditUnfocusable; - +class Event_AddToList; class Event_ListRooms; +class Event_RemoveFromList; class Event_UserJoined; class Event_UserLeft; +class LineEditUnfocusable; class Response; class ServerInfo_User; -class Event_AddToList; -class Event_RemoveFromList; +class UserInfoBox; +class UserListWidget; class TabAccount : public Tab { @@ -24,6 +23,7 @@ signals: void openMessageDialog(const QString &userName, bool focus); void userLeft(const QString &userName); void userJoined(const ServerInfo_User &userInfo); + private slots: void processListUsersResponse(const Response &response); void processUserJoinedEvent(const Event_UserJoined &event); @@ -46,9 +46,9 @@ private: void addToList(const std::string &listName, const QString &userName); public: - TabAccount(TabSupervisor *_tabSupervisor, AbstractClient *_client, const ServerInfo_User &userInfo); + explicit TabAccount(TabSupervisor *_tabSupervisor, AbstractClient *_client, const ServerInfo_User &userInfo); void retranslateUi() override; - QString getTabText() const override + [[nodiscard]] QString getTabText() const override { return tr("Account"); } diff --git a/cockatrice/src/client/tabs/tab_deck_editor.cpp b/cockatrice/src/client/tabs/tab_deck_editor.cpp index f9e73356d..8e76df87a 100644 --- a/cockatrice/src/client/tabs/tab_deck_editor.cpp +++ b/cockatrice/src/client/tabs/tab_deck_editor.cpp @@ -3,7 +3,6 @@ #include "../../client/game_logic/abstract_client.h" #include "../../client/tapped_out_interface.h" #include "../../client/ui/widgets/cards/card_info_frame_widget.h" -#include "../../deck/deck_list_model.h" #include "../../deck/deck_stats_interface.h" #include "../../dialogs/dlg_load_deck.h" #include "../../dialogs/dlg_load_deck_from_clipboard.h" @@ -16,7 +15,6 @@ #include "../../settings/cache_settings.h" #include "../ui/picture_loader/picture_loader.h" #include "../ui/pixel_map_generator.h" -#include "../ui/widgets/printing_selector/printing_selector.h" #include "pb/command_deck_upload.pb.h" #include "pb/response.pb.h" #include "tab_supervisor.h" @@ -891,8 +889,9 @@ void TabDeckEditor::updateBannerCardComboBox() void TabDeckEditor::setBannerCard(int /* changedIndex */) { - QVariantMap data = bannerCardComboBox->itemData(bannerCardComboBox->currentIndex()).toMap(); - deckModel->getDeckList()->setBannerCard(QPair(data["name"].toString(), data["uuid"].toString())); + QVariantMap itemData = bannerCardComboBox->itemData(bannerCardComboBox->currentIndex()).toMap(); + deckModel->getDeckList()->setBannerCard( + QPair(itemData["name"].toString(), itemData["uuid"].toString())); } void TabDeckEditor::updateCardInfo(CardInfoPtr _card) @@ -1411,16 +1410,16 @@ void TabDeckEditor::actSwapCard() deckView->setSelectionMode(QAbstractItemView::SingleSelection); } - bool modified = false; + bool isModified = false; for (const auto ¤tIndex : selectedRows) { if (swapCard(currentIndex)) { - modified = true; + isModified = true; } } deckView->setSelectionMode(QAbstractItemView::ExtendedSelection); - if (modified) { + if (isModified) { setModified(true); setSaveStatus(true); } @@ -1483,18 +1482,18 @@ void TabDeckEditor::actRemoveCard() deckView->setSelectionMode(QAbstractItemView::SingleSelection); } - bool modified = false; + bool isModified = false; for (const auto &index : selectedRows) { if (!index.isValid() || deckModel->hasChildren(index)) { continue; } deckModel->removeRow(index.row(), index.parent()); - modified = true; + isModified = true; } deckView->setSelectionMode(QAbstractItemView::ExtendedSelection); - if (modified) { + if (isModified) { DeckLoader *const deck = deckModel->getDeckList(); setSaveStatus(!deck->isEmpty()); setModified(true); diff --git a/cockatrice/src/client/tabs/tab_supervisor.cpp b/cockatrice/src/client/tabs/tab_supervisor.cpp index 594c1b732..0c2cc3a3d 100644 --- a/cockatrice/src/client/tabs/tab_supervisor.cpp +++ b/cockatrice/src/client/tabs/tab_supervisor.cpp @@ -11,7 +11,6 @@ #include "pb/event_user_message.pb.h" #include "pb/game_event_container.pb.h" #include "pb/game_replay.pb.h" -#include "pb/moderator_commands.pb.h" #include "pb/room_commands.pb.h" #include "pb/room_event.pb.h" #include "pb/serverinfo_room.pb.h" @@ -29,7 +28,6 @@ #include "visual_deck_storage/tab_deck_storage_visual.h" #include -#include #include #include #include @@ -50,15 +48,15 @@ CloseButton::CloseButton(QWidget *parent) : QAbstractButton(parent) { setFocusPolicy(Qt::NoFocus); setCursor(Qt::ArrowCursor); - resize(sizeHint()); + resize(this->sizeHint()); } QSize CloseButton::sizeHint() const { ensurePolished(); - int width = style()->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, 0, this); - int height = style()->pixelMetric(QStyle::PM_TabCloseIndicatorHeight, 0, this); - return QSize(width, height); + int width = style()->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, nullptr, this); + int height = style()->pixelMetric(QStyle::PM_TabCloseIndicatorHeight, nullptr, this); + return {width, height}; } #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) @@ -90,10 +88,9 @@ void CloseButton::paintEvent(QPaintEvent * /*event*/) if (isDown()) opt.state |= QStyle::State_Sunken; - if (const QTabBar *tb = qobject_cast(parent())) { + if (const auto *tb = qobject_cast(parent())) { int index = tb->currentIndex(); - QTabBar::ButtonPosition position = - (QTabBar::ButtonPosition)style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, 0, tb); + auto position = (QTabBar::ButtonPosition)style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, nullptr, tb); if (tb->tabButton(index, position) == this) opt.state |= QStyle::State_Selected; } @@ -102,8 +99,9 @@ void CloseButton::paintEvent(QPaintEvent * /*event*/) } TabSupervisor::TabSupervisor(AbstractClient *_client, QMenu *tabsMenu, QWidget *parent) - : QTabWidget(parent), userInfo(0), client(_client), tabsMenu(tabsMenu), tabVisualDeckStorage(nullptr), tabServer(0), - tabAccount(0), tabDeckStorage(0), tabReplays(0), tabAdmin(0), tabLog(0) + : QTabWidget(parent), userInfo(nullptr), client(_client), tabsMenu(tabsMenu), tabVisualDeckStorage(nullptr), + tabServer(nullptr), tabAccount(nullptr), tabDeckStorage(nullptr), tabReplays(nullptr), tabAdmin(nullptr), + tabLog(nullptr), isLocalGame(false) { setElideMode(Qt::ElideRight); setMovable(true); @@ -210,14 +208,15 @@ void TabSupervisor::retranslateUi() while (messageIterator.hasNext()) tabs.append(messageIterator.next().value()); - for (int i = 0; i < tabs.size(); ++i) - if (tabs[i]) { - int idx = indexOf(tabs[i]); - QString tabText = tabs[i]->getTabText(); + for (auto &tab : tabs) { + if (tab) { + int idx = indexOf(tab); + QString tabText = tab->getTabText(); setTabText(idx, sanitizeTabName(tabText)); setTabToolTip(idx, sanitizeHtml(tabText)); - tabs[i]->retranslateUi(); + tab->retranslateUi(); } + } } void TabSupervisor::refreshShortcuts() @@ -249,12 +248,12 @@ AbstractClient *TabSupervisor::getClient() const return localClients.isEmpty() ? client : localClients.first(); } -QString TabSupervisor::sanitizeTabName(QString dirty) const +QString TabSupervisor::sanitizeTabName(QString dirty) { return dirty.replace("&", "&&"); } -QString TabSupervisor::sanitizeHtml(QString dirty) const +QString TabSupervisor::sanitizeHtml(QString dirty) { return dirty.replace("&", "&").replace("<", "<").replace(">", ">").replace("\"", """); } @@ -379,11 +378,11 @@ void TabSupervisor::startLocal(const QList &_clients) { resetTabsMenu(); - tabAccount = 0; - tabDeckStorage = 0; - tabReplays = 0; - tabAdmin = 0; - tabLog = 0; + tabAccount = nullptr; + tabDeckStorage = nullptr; + tabReplays = nullptr; + tabAdmin = nullptr; + tabLog = nullptr; isLocalGame = true; userInfo = new ServerInfo_User; localClients = _clients; @@ -404,8 +403,9 @@ void TabSupervisor::stop() resetTabsMenu(); if (!localClients.isEmpty()) { - for (int i = 0; i < localClients.size(); ++i) - localClients[i]->deleteLater(); + for (auto &localClient : localClients) { + localClient->deleteLater(); + } localClients.clear(); emit localGameEnded(); @@ -451,14 +451,14 @@ void TabSupervisor::stop() userListManager->handleDisconnect(); delete userInfo; - userInfo = 0; + userInfo = nullptr; } void TabSupervisor::actTabVisualDeckStorage(bool checked) { SettingsCache::instance().setTabVisualDeckStorageOpen(checked); if (checked && !tabVisualDeckStorage) { - tabVisualDeckStorage = new TabDeckStorageVisual(this, client); + tabVisualDeckStorage = new TabDeckStorageVisual(this); myAddTab(tabVisualDeckStorage, aTabVisualDeckStorage); setCurrentWidget(tabVisualDeckStorage); connect(tabVisualDeckStorage, &Tab::closed, this, [this] { @@ -588,7 +588,7 @@ void TabSupervisor::gameJoined(const Event_GameJoined &event) roomGameTypes.insert(event.game_types(i).game_type_id(), QString::fromStdString(event.game_types(i).description())); - TabGame *tab = new TabGame(this, userListManager, QList() << client, event, roomGameTypes); + auto *tab = new TabGame(this, userListManager, QList() << client, event, roomGameTypes); connect(tab, &TabGame::gameClosing, this, &TabSupervisor::gameLeft); connect(tab, &TabGame::openMessageDialog, this, &TabSupervisor::addMessageTab); connect(tab, &TabGame::openDeckEditor, this, &TabSupervisor::addDeckEditorTab); @@ -599,7 +599,7 @@ void TabSupervisor::gameJoined(const Event_GameJoined &event) void TabSupervisor::localGameJoined(const Event_GameJoined &event) { - TabGame *tab = new TabGame(this, userListManager, localClients, event, QMap()); + auto *tab = new TabGame(this, userListManager, localClients, event, QMap()); connect(tab, &TabGame::gameClosing, this, &TabSupervisor::gameLeft); connect(tab, &TabGame::openDeckEditor, this, &TabSupervisor::addDeckEditorTab); myAddTab(tab); @@ -627,7 +627,7 @@ void TabSupervisor::gameLeft(TabGame *tab) void TabSupervisor::addRoomTab(const ServerInfo_Room &info, bool setCurrent) { - TabRoom *tab = new TabRoom(this, client, userInfo, userListManager, info); + auto *tab = new TabRoom(this, client, userInfo, userListManager, info); connect(tab, &TabRoom::maximizeClient, this, &TabSupervisor::maximizeMainWindow); connect(tab, &TabRoom::roomClosing, this, &TabSupervisor::roomLeft); connect(tab, &TabRoom::openMessageDialog, this, &TabSupervisor::addMessageTab); @@ -648,7 +648,7 @@ void TabSupervisor::roomLeft(TabRoom *tab) void TabSupervisor::openReplay(GameReplay *replay) { - TabGame *replayTab = new TabGame(this, replay); + auto *replayTab = new TabGame(this, replay); connect(replayTab, &TabGame::gameClosing, this, &TabSupervisor::replayLeft); myAddTab(replayTab); replayTabs.append(replayTab); @@ -709,7 +709,7 @@ void TabSupervisor::talkLeft(TabMessage *tab) TabDeckEditor *TabSupervisor::addDeckEditorTab(const DeckLoader *deckToOpen) { - TabDeckEditor *tab = new TabDeckEditor(this); + auto *tab = new TabDeckEditor(this); if (deckToOpen) tab->setDeck(new DeckLoader(*deckToOpen)); connect(tab, &TabDeckEditor::deckEditorClosing, this, &TabSupervisor::deckEditorClosed); @@ -770,9 +770,9 @@ void TabSupervisor::processUserMessageEvent(const Event_UserMessage &event) if (!tab) tab = messageTabs.value(QString::fromStdString(event.receiver_name())); if (!tab) { - const ServerInfo_User *userInfo = userListManager->getOnlineUser(senderName); - if (userInfo) { - UserLevelFlags userLevel = UserLevelFlags(userInfo->user_level()); + const ServerInfo_User *onlineUserInfo = userListManager->getOnlineUser(senderName); + if (onlineUserInfo) { + auto userLevel = UserLevelFlags(onlineUserInfo->user_level()); if (SettingsCache::instance().getIgnoreUnregisteredUserMessages() && !userLevel.testFlag(ServerInfo_User::IsRegistered)) // Flags are additive, so reg/mod/admin are all IsRegistered diff --git a/cockatrice/src/client/tabs/tab_supervisor.h b/cockatrice/src/client/tabs/tab_supervisor.h index 912f6df27..ad463f3ba 100644 --- a/cockatrice/src/client/tabs/tab_supervisor.h +++ b/cockatrice/src/client/tabs/tab_supervisor.h @@ -91,8 +91,8 @@ private: int myAddTab(Tab *tab, QAction *manager = nullptr); void addCloseButtonToTab(Tab *tab, int tabIndex, QAction *manager); - QString sanitizeTabName(QString dirty) const; - QString sanitizeHtml(QString dirty) const; + static QString sanitizeTabName(QString dirty); + static QString sanitizeHtml(QString dirty); void resetTabsMenu(); public: @@ -131,7 +131,7 @@ public: bool getAdminLocked() const; bool closeRequest(); bool switchToGameTabIfAlreadyExists(const int gameId); - void actShowPopup(const QString &message); + static void actShowPopup(const QString &message); signals: void setMenu(const QList &newMenuList = QList()); void localGameEnded(); diff --git a/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.cpp b/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.cpp index 39e7a1606..728473d8a 100644 --- a/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.cpp +++ b/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.cpp @@ -1,99 +1,33 @@ #include "tab_deck_storage_visual.h" #include "../../../game/cards/card_database_model.h" +#include "../../ui/widgets/cards/deck_preview_card_picture_widget.h" +#include "../../ui/widgets/visual_deck_storage/visual_deck_storage_widget.h" #include "../tab_supervisor.h" #include "pb/command_deck_del.pb.h" -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -class FlowLayout; -TabDeckStorageVisual::TabDeckStorageVisual(TabSupervisor *_tabSupervisor, AbstractClient *_client) - : Tab(_tabSupervisor), client(_client) +TabDeckStorageVisual::TabDeckStorageVisual(TabSupervisor *_tabSupervisor) + : Tab(_tabSupervisor), visualDeckStorageWidget(new VisualDeckStorageWidget(this)) { - deck_list_model = new DeckListModel(this); - deck_list_model->setObjectName("visualDeckModel"); - - QWidget *container = new QWidget(this); - QVBoxLayout *layout = new QVBoxLayout(container); - container->setLayout(layout); - this->setCentralWidget(container); - - leftToolBar = new QToolBar; - leftToolBar->setOrientation(Qt::Horizontal); - leftToolBar->setIconSize(QSize(32, 32)); - QHBoxLayout *leftToolBarLayout = new QHBoxLayout(this); - leftToolBarLayout->addStretch(); - leftToolBarLayout->addWidget(leftToolBar); - leftToolBarLayout->addStretch(); - - aOpenLocalDeck = new QAction(this); - aOpenLocalDeck->setIcon(QPixmap("theme:icons/pencil")); - connect(aOpenLocalDeck, SIGNAL(triggered()), this, SLOT(actOpenLocalDeck())); - aDeleteLocalDeck = new QAction(this); - aDeleteLocalDeck->setIcon(QPixmap("theme:icons/remove_row")); - connect(aDeleteLocalDeck, SIGNAL(triggered()), this, SLOT(actDeleteLocalDeck())); - connect(this, &TabDeckStorageVisual::openDeckEditor, tabSupervisor, &TabSupervisor::addDeckEditorTab); - - leftToolBar->addAction(aOpenLocalDeck); - leftToolBar->addAction(aDeleteLocalDeck); - - visualDeckStorageWidget = new VisualDeckStorageWidget(this); connect(visualDeckStorageWidget, &VisualDeckStorageWidget::deckPreviewDoubleClicked, this, &TabDeckStorageVisual::actOpenLocalDeck); - // layout->addWidget(leftToolBar); + auto *widget = new QWidget(this); + auto *layout = new QVBoxLayout(widget); + widget->setLayout(layout); + this->setCentralWidget(widget); layout->addWidget(visualDeckStorageWidget); - - retranslateUi(); } -void TabDeckStorageVisual::retranslateUi() +void TabDeckStorageVisual::actOpenLocalDeck(QMouseEvent * /*event*/, DeckPreviewWidget *instance) { - aOpenLocalDeck->setText(tr("Open in deck editor")); - aDeleteLocalDeck->setText(tr("Delete")); -} - -QString TabDeckStorageVisual::getTargetPath() const -{ - return {}; -} - -void TabDeckStorageVisual::actOpenLocalDeck(QMouseEvent *event, DeckPreviewWidget *instance) -{ - (void)event; DeckLoader deckLoader; - if (!deckLoader.loadFromFile(instance->filePath, DeckLoader::CockatriceFormat, true)) + if (!deckLoader.loadFromFile(instance->filePath, DeckLoader::CockatriceFormat, true)) { return; + } emit openDeckEditor(&deckLoader); } - -void TabDeckStorageVisual::actDeleteLocalDeck() -{ - QModelIndex curLeft = localDirView->selectionModel()->currentIndex(); - if (localDirModel->isDir(curLeft)) - return; - - if (QMessageBox::warning(this, tr("Delete local file"), - tr("Are you sure you want to delete \"%1\"?").arg(localDirModel->fileName(curLeft)), - QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) - return; - - localDirModel->remove(curLeft); -} - -void TabDeckStorageVisual::cardUpdateFinished(int exitCode, QProcess::ExitStatus exitStatus) -{ - qDebug() << "Card update process finished with exit code:" << exitCode << "and exit status:" << exitStatus; -} diff --git a/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.h b/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.h index dd705a441..b5554de42 100644 --- a/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.h +++ b/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.h @@ -1,54 +1,40 @@ #ifndef TAB_DECK_STORAGE_VISUAL_H #define TAB_DECK_STORAGE_VISUAL_H -#include "../../../deck/deck_list_model.h" -#include "../../ui/widgets/cards/deck_preview_card_picture_widget.h" -#include "../../ui/widgets/visual_deck_storage/visual_deck_storage_widget.h" #include "../tab.h" -#include - class AbstractClient; -class QTreeView; +class CommandContainer; +class DeckLoader; +class DeckPreviewWidget; class QFileSystemModel; +class QGroupBox; class QToolBar; +class QTreeView; class QTreeWidget; class QTreeWidgetItem; -class QGroupBox; -class CommandContainer; class Response; -class DeckLoader; +class VisualDeckStorageWidget; class TabDeckStorageVisual final : public Tab { Q_OBJECT public: - TabDeckStorageVisual(TabSupervisor *_tabSupervisor, AbstractClient *_client); - - void retranslateUi() override; - QString getTabText() const override + explicit TabDeckStorageVisual(TabSupervisor *_tabSupervisor); + void retranslateUi() override{}; + [[nodiscard]] QString getTabText() const override { return tr("Visual Deck storage"); } + public slots: - void cardUpdateFinished(int exitCode, QProcess::ExitStatus exitStatus); - void actOpenLocalDeck(QMouseEvent *event, DeckPreviewWidget *instance); - void actDeleteLocalDeck(); + void actOpenLocalDeck(QMouseEvent * /*event*/, DeckPreviewWidget *instance); + signals: void openDeckEditor(const DeckLoader *deckLoader); private: - QWidget *container; - QHBoxLayout *layout; - AbstractClient *client; - QTreeView *localDirView; - QFileSystemModel *localDirModel; - QToolBar *leftToolBar; - QGroupBox *leftGroupBox; VisualDeckStorageWidget *visualDeckStorageWidget; - DeckListModel *deck_list_model; - QAction *aOpenLocalDeck, *aDeleteLocalDeck; - QString getTargetPath() const; }; #endif diff --git a/cockatrice/src/client/ui/widgets/visual_deck_storage/visual_deck_storage_widget.cpp b/cockatrice/src/client/ui/widgets/visual_deck_storage/visual_deck_storage_widget.cpp index f7faeb647..ba55f0bd8 100644 --- a/cockatrice/src/client/ui/widgets/visual_deck_storage/visual_deck_storage_widget.cpp +++ b/cockatrice/src/client/ui/widgets/visual_deck_storage/visual_deck_storage_widget.cpp @@ -1,6 +1,5 @@ #include "visual_deck_storage_widget.h" -#include "../../../../deck/deck_loader.h" #include "../../../../game/cards/card_database_manager.h" #include "../../../../settings/cache_settings.h" #include "deck_preview/deck_preview_widget.h"