mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-04 12:33:55 -07:00
Refactor TabReplay creation (#6064)
This commit is contained in:
parent
851fad3e3f
commit
881243da6a
2 changed files with 76 additions and 60 deletions
|
|
@ -29,6 +29,29 @@
|
||||||
|
|
||||||
TabReplays::TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client, const ServerInfo_User *currentUserInfo)
|
TabReplays::TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client, const ServerInfo_User *currentUserInfo)
|
||||||
: Tab(_tabSupervisor), client(_client)
|
: Tab(_tabSupervisor), client(_client)
|
||||||
|
{
|
||||||
|
leftGroupBox = createLeftLayout();
|
||||||
|
rightGroupBox = createRightLayout();
|
||||||
|
|
||||||
|
// combine layouts
|
||||||
|
QHBoxLayout *hbox = new QHBoxLayout;
|
||||||
|
hbox->addWidget(leftGroupBox);
|
||||||
|
hbox->addWidget(rightGroupBox);
|
||||||
|
|
||||||
|
retranslateUi();
|
||||||
|
|
||||||
|
QWidget *mainWidget = new QWidget(this);
|
||||||
|
mainWidget->setLayout(hbox);
|
||||||
|
setCentralWidget(mainWidget);
|
||||||
|
|
||||||
|
connect(client, &AbstractClient::replayAddedEventReceived, this, &TabReplays::replayAddedEventReceived);
|
||||||
|
|
||||||
|
connect(client, &AbstractClient::userInfoChanged, this, &TabReplays::handleConnected);
|
||||||
|
connect(client, &AbstractClient::statusChanged, this, &TabReplays::handleConnectionChanged);
|
||||||
|
setRemoteEnabled(currentUserInfo && currentUserInfo->user_level() & ServerInfo_User::IsRegistered);
|
||||||
|
}
|
||||||
|
|
||||||
|
QGroupBox *TabReplays::createLeftLayout()
|
||||||
{
|
{
|
||||||
localDirModel = new QFileSystemModel(this);
|
localDirModel = new QFileSystemModel(this);
|
||||||
localDirModel->setRootPath(SettingsCache::instance().getReplaysPath());
|
localDirModel->setRootPath(SettingsCache::instance().getReplaysPath());
|
||||||
|
|
@ -52,46 +75,24 @@ TabReplays::TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client, c
|
||||||
dummyToolBar->setSizePolicy(sizePolicy);
|
dummyToolBar->setSizePolicy(sizePolicy);
|
||||||
dummyToolBar->setVisible(false);
|
dummyToolBar->setVisible(false);
|
||||||
|
|
||||||
leftToolBar = new QToolBar(this);
|
QToolBar *toolBar = new QToolBar(this);
|
||||||
leftToolBar->setOrientation(Qt::Horizontal);
|
toolBar->setOrientation(Qt::Horizontal);
|
||||||
leftToolBar->setIconSize(QSize(32, 32));
|
toolBar->setIconSize(QSize(32, 32));
|
||||||
|
|
||||||
QToolBar *leftRightmostToolBar = new QToolBar(this);
|
QToolBar *rightmostToolBar = new QToolBar(this);
|
||||||
leftRightmostToolBar->setOrientation(Qt::Horizontal);
|
rightmostToolBar->setOrientation(Qt::Horizontal);
|
||||||
leftRightmostToolBar->setIconSize(QSize(32, 32));
|
rightmostToolBar->setIconSize(QSize(32, 32));
|
||||||
|
|
||||||
QGridLayout *leftToolBarLayout = new QGridLayout;
|
QGridLayout *toolBarLayout = new QGridLayout;
|
||||||
leftToolBarLayout->addWidget(dummyToolBar, 0, 0, Qt::AlignLeft);
|
toolBarLayout->addWidget(dummyToolBar, 0, 0, Qt::AlignLeft);
|
||||||
leftToolBarLayout->addWidget(leftToolBar, 0, 1, Qt::AlignHCenter);
|
toolBarLayout->addWidget(toolBar, 0, 1, Qt::AlignHCenter);
|
||||||
leftToolBarLayout->addWidget(leftRightmostToolBar, 0, 2, Qt::AlignRight);
|
toolBarLayout->addWidget(rightmostToolBar, 0, 2, Qt::AlignRight);
|
||||||
|
|
||||||
QVBoxLayout *leftVbox = new QVBoxLayout;
|
QVBoxLayout *vbox = new QVBoxLayout;
|
||||||
leftVbox->addWidget(localDirView);
|
vbox->addWidget(localDirView);
|
||||||
leftVbox->addLayout(leftToolBarLayout);
|
vbox->addLayout(toolBarLayout);
|
||||||
leftGroupBox = new QGroupBox;
|
QGroupBox *groupBox = new QGroupBox;
|
||||||
leftGroupBox->setLayout(leftVbox);
|
groupBox->setLayout(vbox);
|
||||||
|
|
||||||
// Right side layout
|
|
||||||
rightToolBar = new QToolBar;
|
|
||||||
rightToolBar->setOrientation(Qt::Horizontal);
|
|
||||||
rightToolBar->setIconSize(QSize(32, 32));
|
|
||||||
QHBoxLayout *rightToolBarLayout = new QHBoxLayout;
|
|
||||||
rightToolBarLayout->addStretch();
|
|
||||||
rightToolBarLayout->addWidget(rightToolBar);
|
|
||||||
rightToolBarLayout->addStretch();
|
|
||||||
|
|
||||||
serverDirView = new RemoteReplayList_TreeWidget(client);
|
|
||||||
|
|
||||||
QVBoxLayout *rightVbox = new QVBoxLayout;
|
|
||||||
rightVbox->addWidget(serverDirView);
|
|
||||||
rightVbox->addLayout(rightToolBarLayout);
|
|
||||||
rightGroupBox = new QGroupBox;
|
|
||||||
rightGroupBox->setLayout(rightVbox);
|
|
||||||
|
|
||||||
// combine layouts
|
|
||||||
QHBoxLayout *hbox = new QHBoxLayout;
|
|
||||||
hbox->addWidget(leftGroupBox);
|
|
||||||
hbox->addWidget(rightGroupBox);
|
|
||||||
|
|
||||||
// Left side actions
|
// Left side actions
|
||||||
aOpenLocalReplay = new QAction(this);
|
aOpenLocalReplay = new QAction(this);
|
||||||
|
|
@ -112,6 +113,36 @@ TabReplays::TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client, c
|
||||||
aOpenReplaysFolder->setIcon(qApp->style()->standardIcon(QStyle::SP_DirOpenIcon));
|
aOpenReplaysFolder->setIcon(qApp->style()->standardIcon(QStyle::SP_DirOpenIcon));
|
||||||
connect(aOpenReplaysFolder, &QAction::triggered, this, &TabReplays::actOpenReplaysFolder);
|
connect(aOpenReplaysFolder, &QAction::triggered, this, &TabReplays::actOpenReplaysFolder);
|
||||||
|
|
||||||
|
// Add actions to toolbars
|
||||||
|
toolBar->addAction(aOpenLocalReplay);
|
||||||
|
toolBar->addAction(aRenameLocal);
|
||||||
|
toolBar->addAction(aNewLocalFolder);
|
||||||
|
toolBar->addAction(aDeleteLocalReplay);
|
||||||
|
|
||||||
|
rightmostToolBar->addAction(aOpenReplaysFolder);
|
||||||
|
|
||||||
|
return groupBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
QGroupBox *TabReplays::createRightLayout()
|
||||||
|
{
|
||||||
|
serverDirView = new RemoteReplayList_TreeWidget(client);
|
||||||
|
|
||||||
|
// Right side layout
|
||||||
|
QToolBar *toolBar = new QToolBar;
|
||||||
|
toolBar->setOrientation(Qt::Horizontal);
|
||||||
|
toolBar->setIconSize(QSize(32, 32));
|
||||||
|
QHBoxLayout *toolBarLayout = new QHBoxLayout;
|
||||||
|
toolBarLayout->addStretch();
|
||||||
|
toolBarLayout->addWidget(toolBar);
|
||||||
|
toolBarLayout->addStretch();
|
||||||
|
|
||||||
|
QVBoxLayout *vbox = new QVBoxLayout;
|
||||||
|
vbox->addWidget(serverDirView);
|
||||||
|
vbox->addLayout(toolBarLayout);
|
||||||
|
QGroupBox *groupBox = new QGroupBox;
|
||||||
|
groupBox->setLayout(vbox);
|
||||||
|
|
||||||
// Right side actions
|
// Right side actions
|
||||||
aOpenRemoteReplay = new QAction(this);
|
aOpenRemoteReplay = new QAction(this);
|
||||||
aOpenRemoteReplay->setIcon(QPixmap("theme:icons/view"));
|
aOpenRemoteReplay->setIcon(QPixmap("theme:icons/view"));
|
||||||
|
|
@ -128,29 +159,12 @@ TabReplays::TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client, c
|
||||||
connect(aDeleteRemoteReplay, &QAction::triggered, this, &TabReplays::actDeleteRemoteReplay);
|
connect(aDeleteRemoteReplay, &QAction::triggered, this, &TabReplays::actDeleteRemoteReplay);
|
||||||
|
|
||||||
// Add actions to toolbars
|
// Add actions to toolbars
|
||||||
leftToolBar->addAction(aOpenLocalReplay);
|
toolBar->addAction(aOpenRemoteReplay);
|
||||||
leftToolBar->addAction(aRenameLocal);
|
toolBar->addAction(aDownload);
|
||||||
leftToolBar->addAction(aNewLocalFolder);
|
toolBar->addAction(aKeep);
|
||||||
leftToolBar->addAction(aDeleteLocalReplay);
|
toolBar->addAction(aDeleteRemoteReplay);
|
||||||
|
|
||||||
leftRightmostToolBar->addAction(aOpenReplaysFolder);
|
return groupBox;
|
||||||
|
|
||||||
rightToolBar->addAction(aOpenRemoteReplay);
|
|
||||||
rightToolBar->addAction(aDownload);
|
|
||||||
rightToolBar->addAction(aKeep);
|
|
||||||
rightToolBar->addAction(aDeleteRemoteReplay);
|
|
||||||
|
|
||||||
retranslateUi();
|
|
||||||
|
|
||||||
QWidget *mainWidget = new QWidget(this);
|
|
||||||
mainWidget->setLayout(hbox);
|
|
||||||
setCentralWidget(mainWidget);
|
|
||||||
|
|
||||||
connect(client, &AbstractClient::replayAddedEventReceived, this, &TabReplays::replayAddedEventReceived);
|
|
||||||
|
|
||||||
connect(client, &AbstractClient::userInfoChanged, this, &TabReplays::handleConnected);
|
|
||||||
connect(client, &AbstractClient::statusChanged, this, &TabReplays::handleConnectionChanged);
|
|
||||||
setRemoteEnabled(currentUserInfo && currentUserInfo->user_level() & ServerInfo_User::IsRegistered);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabReplays::retranslateUi()
|
void TabReplays::retranslateUi()
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ private:
|
||||||
AbstractClient *client;
|
AbstractClient *client;
|
||||||
QTreeView *localDirView;
|
QTreeView *localDirView;
|
||||||
QFileSystemModel *localDirModel;
|
QFileSystemModel *localDirModel;
|
||||||
QToolBar *leftToolBar, *rightToolBar;
|
|
||||||
RemoteReplayList_TreeWidget *serverDirView;
|
RemoteReplayList_TreeWidget *serverDirView;
|
||||||
QGroupBox *leftGroupBox, *rightGroupBox;
|
QGroupBox *leftGroupBox, *rightGroupBox;
|
||||||
|
|
||||||
|
|
@ -31,6 +30,9 @@ private:
|
||||||
QAction *aOpenReplaysFolder;
|
QAction *aOpenReplaysFolder;
|
||||||
QAction *aOpenRemoteReplay, *aDownload, *aKeep, *aDeleteRemoteReplay;
|
QAction *aOpenRemoteReplay, *aDownload, *aKeep, *aDeleteRemoteReplay;
|
||||||
|
|
||||||
|
QGroupBox *createLeftLayout();
|
||||||
|
QGroupBox *createRightLayout();
|
||||||
|
|
||||||
void setRemoteEnabled(bool enabled);
|
void setRemoteEnabled(bool enabled);
|
||||||
|
|
||||||
void downloadNodeAtIndex(const QModelIndex &curLeft, const QModelIndex &curRight);
|
void downloadNodeAtIndex(const QModelIndex &curLeft, const QModelIndex &curRight);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue