From a082fbcfef585cdaabf24351667598fe258e6aab Mon Sep 17 00:00:00 2001 From: Matt Lowe Date: Thu, 2 Apr 2015 12:49:06 +0200 Subject: [PATCH] Left hand justification Set to false by default, let me know if you think it should be true. As all cards are played to the left of the screen this feels more comfortable to use as you dont need to keep looking at different areas of the screen. Will auto rearrange when changed during game-play. --- cockatrice/src/dlg_settings.cpp | 5 +++++ cockatrice/src/dlg_settings.h | 1 + cockatrice/src/handzone.cpp | 13 ++++++++----- cockatrice/src/player.cpp | 1 + cockatrice/src/settingscache.cpp | 8 ++++++++ cockatrice/src/settingscache.h | 4 ++++ 6 files changed, 27 insertions(+), 5 deletions(-) diff --git a/cockatrice/src/dlg_settings.cpp b/cockatrice/src/dlg_settings.cpp index 13f72b39..5163ffa2 100644 --- a/cockatrice/src/dlg_settings.cpp +++ b/cockatrice/src/dlg_settings.cpp @@ -309,9 +309,13 @@ AppearanceSettingsPage::AppearanceSettingsPage() horizontalHandCheckBox.setChecked(settingsCache->getHorizontalHand()); connect(&horizontalHandCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setHorizontalHand(int))); + + leftJustifiedHandCheckBox.setChecked(settingsCache->getLeftJustified()); + connect(&leftJustifiedHandCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setLeftJustified(int))); QGridLayout *handGrid = new QGridLayout; handGrid->addWidget(&horizontalHandCheckBox, 0, 0, 1, 2); + handGrid->addWidget(&leftJustifiedHandCheckBox, 1, 0, 1, 2); handGroupBox = new QGroupBox; handGroupBox->setLayout(handGrid); @@ -356,6 +360,7 @@ void AppearanceSettingsPage::retranslateUi() handGroupBox->setTitle(tr("Hand layout")); horizontalHandCheckBox.setText(tr("Display hand horizontally (wastes space)")); + leftJustifiedHandCheckBox.setText(tr("Enable left justification")); tableGroupBox->setTitle(tr("Table grid layout")); invertVerticalCoordinateCheckBox.setText(tr("Invert vertical coordinate")); diff --git a/cockatrice/src/dlg_settings.h b/cockatrice/src/dlg_settings.h index c83f2b6d..aa6cefa2 100644 --- a/cockatrice/src/dlg_settings.h +++ b/cockatrice/src/dlg_settings.h @@ -100,6 +100,7 @@ private: QCheckBox displayCardNamesCheckBox; QCheckBox cardScalingCheckBox; QCheckBox horizontalHandCheckBox; + QCheckBox leftJustifiedHandCheckBox; QCheckBox invertVerticalCoordinateCheckBox; QGroupBox *zoneBgGroupBox; QGroupBox *cardsGroupBox; diff --git a/cockatrice/src/handzone.cpp b/cockatrice/src/handzone.cpp index 3a4e6f1d..f94f5be0 100644 --- a/cockatrice/src/handzone.cpp +++ b/cockatrice/src/handzone.cpp @@ -88,19 +88,22 @@ void HandZone::reorganizeCards() if (!cards.isEmpty()) { const int cardCount = cards.size(); if (settingsCache->getHorizontalHand()) { - const int xPadding = 5; - qreal totalWidth = boundingRect().width() - 2 * xPadding; + bool leftJustified = settingsCache->getLeftJustified(); qreal cardWidth = cards.at(0)->boundingRect().width(); + const int xPadding = leftJustified ? cardWidth * 1.4 : 5; + qreal totalWidth = leftJustified? boundingRect().width() - (1 * xPadding) - 5 : boundingRect().width() - 2 * xPadding; for (int i = 0; i < cardCount; i++) { CardItem *c = cards.at(i); - // If the total width of the cards is smaller than the available width, // the cards do not need to overlap and are displayed in the center of the area. if (cardWidth * cardCount > totalWidth) c->setPos(xPadding + ((qreal) i) * (totalWidth - cardWidth) / (cardCount - 1), 5); - else - c->setPos(xPadding + ((qreal) i) * cardWidth + (totalWidth - cardCount * cardWidth) / 2, 5); + else { + qreal xPosition = leftJustified ? xPadding + ((qreal) i) * cardWidth : + xPadding + ((qreal) i) * cardWidth + (totalWidth - cardCount * cardWidth) / 2; + c->setPos(xPosition, 5); + } c->setRealZValue(i); } } else { diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index 1cd910df..54f90ea2 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -115,6 +115,7 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, TabGame *_pare userInfo->CopyFrom(info); connect(settingsCache, SIGNAL(horizontalHandChanged()), this, SLOT(rearrangeZones())); + connect(settingsCache, SIGNAL(handJustificationChanged()), this, SLOT(rearrangeZones())); playerArea = new PlayerArea(this); diff --git a/cockatrice/src/settingscache.cpp b/cockatrice/src/settingscache.cpp index 552c1b81..e605619e 100644 --- a/cockatrice/src/settingscache.cpp +++ b/cockatrice/src/settingscache.cpp @@ -77,6 +77,14 @@ SettingsCache::SettingsCache() scaleCards = settings->value("cards/scaleCards", true).toBool(); showMessagePopups = settings->value("chat/showmessagepopups", true).toBool(); showMentionPopups = settings->value("chat/showmentionpopups", true).toBool(); + + leftJustified = settings->value("interface/leftjustified", false).toBool(); +} + +void SettingsCache::setLeftJustified(const int _leftJustified) { + leftJustified = _leftJustified; + settings->setValue("interface/leftjustified", leftJustified); + emit handJustificationChanged(); } void SettingsCache::setCardScaling(const int _scaleCards) { diff --git a/cockatrice/src/settingscache.h b/cockatrice/src/settingscache.h index 2bc59643..eb47f24b 100644 --- a/cockatrice/src/settingscache.h +++ b/cockatrice/src/settingscache.h @@ -30,6 +30,7 @@ signals: void picDownloadHqChanged(); void displayCardNamesChanged(); void horizontalHandChanged(); + void handJustificationChanged(); void invertVerticalCoordinateChanged(); void minPlayersForMultiColumnLayoutChanged(); void soundEnabledChanged(); @@ -77,6 +78,7 @@ private: bool scaleCards; bool showMessagePopups; bool showMentionPopups; + bool leftJustified; public: SettingsCache(); const QByteArray &getMainWindowGeometry() const { return mainWindowGeometry; } @@ -131,6 +133,7 @@ public: bool getScaleCards() const { return scaleCards; } bool getShowMessagePopup() const { return showMessagePopups; } bool getShowMentionPopup() const { return showMentionPopups; } + bool getLeftJustified() const { return leftJustified; } public slots: void setMainWindowGeometry(const QByteArray &_mainWindowGeometry); void setLang(const QString &_lang); @@ -178,6 +181,7 @@ public slots: void setCardScaling(const int _scaleCards); void setShowMessagePopups(const int _showMessagePopups); void setShowMentionPopups(const int _showMentionPopups); + void setLeftJustified( const int _leftJustified); }; extern SettingsCache *settingsCache;