added settings for modifying tabs

This commit is contained in:
fourtf 2017-02-02 02:46:33 +01:00
parent 43cf7620ae
commit 5390272279
8 changed files with 59 additions and 28 deletions

View file

@ -48,6 +48,8 @@ Settings::Settings()
, inlineWhispers(this->settingsItems, "inlineWhispers", true)
, windowTopMost(this->settingsItems, "windowTopMost", false)
, hideTabX(this->settingsItems, "hideTabX", false)
, hidePreferencesButton(this->settingsItems, "hidePreferencesButton", false)
, hideUserButton(this->settingsItems, "hideUserButton", false)
{
this->showTimestamps.valueChanged.connect(
[this](const auto &) { this->updateWordTypeMask(); });

View file

@ -108,6 +108,8 @@ public:
Setting<bool> inlineWhispers;
Setting<bool> windowTopMost;
Setting<bool> hideTabX;
Setting<bool> hidePreferencesButton;
Setting<bool> hideUserButton;
};
} // namespace chatterino

View file

@ -39,6 +39,11 @@ Notebook::Notebook(QWidget *parent)
this->userButton.icon = NotebookButton::IconUser;
this->addButton.resize(24, 24);
Settings::getInstance().hidePreferencesButton.valueChanged.connect(
[this](const bool &) { this->performLayout(); });
Settings::getInstance().hideUserButton.valueChanged.connect(
[this](const bool &) { this->performLayout(); });
}
NotebookPage *
@ -140,7 +145,21 @@ Notebook::rearrangePage(NotebookPage *page, int index)
void
Notebook::performLayout(bool animated)
{
int x = 48, y = 0;
int x = 0, y = 0;
if (Settings::getInstance().hidePreferencesButton.get()) {
settingsButton.hide();
} else {
settingsButton.show();
x += 24;
}
if (Settings::getInstance().hideUserButton.get()) {
userButton.hide();
} else {
userButton.show();
x += 24;
}
int tabHeight = 16;
bool first = true;

View file

@ -76,8 +76,9 @@ NotebookPage::removeFromLayout(ChatWidget *widget)
}
void
NotebookPage::addToLayout(ChatWidget *widget, std::pair<int, int> position =
std::pair<int, int>(-1, -1))
NotebookPage::addToLayout(
ChatWidget *widget,
std::pair<int, int> position = std::pair<int, int>(-1, -1))
{
this->chatWidgets.push_back(widget);

View file

@ -13,6 +13,7 @@
#include <QVector>
#include <QWidget>
#include <boost/property_tree/ptree.hpp>
#include <boost/signals2.hpp>
namespace chatterino {
namespace widgets {

View file

@ -27,25 +27,16 @@ NotebookTab::NotebookTab(Notebook *notebook)
posAnimation.setEasingCurve(QEasingCurve(QEasingCurve::InCubic));
/* XXX(pajlada): Fix this
QObject::connect(&Settings::getInstance().getHideTabX(),
&BoolSetting::valueChanged, this,
&NotebookTab::hideTabXChanged);
*/
// Settings::getInstance().hideTabX.valueChanged.connect(
// boost::bind(&NotebookTab::hideTabXChanged, this));
this->hideXConnection =
Settings::getInstance().hideTabX.valueChanged.connect(
boost::bind(&NotebookTab::hideTabXChanged, this, _1));
this->setMouseTracking(true);
}
NotebookTab::~NotebookTab()
{
/* XXX(pajlada): Fix this
QObject::disconnect(&Settings::getInstance().getHideTabX(),
&BoolSetting::valueChanged, this,
&NotebookTab::hideTabXChanged);
*/
this->hideXConnection.disconnect();
}
void
@ -56,13 +47,15 @@ NotebookTab::calcSize()
} else {
this->resize(this->fontMetrics().width(this->title) + 8 + 24, 24);
}
if (this->parent() != nullptr) {
((Notebook *)this->parent())->performLayout(true);
}
}
void
NotebookTab::moveAnimated(QPoint pos, bool animated)
{
// move(pos);
posAnimationDesired = pos;
if ((this->window() != NULL && !this->window()->isVisible()) || !animated ||
@ -151,7 +144,8 @@ NotebookTab::mouseReleaseEvent(QMouseEvent *event)
{
this->mouseDown = false;
if (this->mouseDownX && this->getXRect().contains(event->pos())) {
if (!Settings::getInstance().hideTabX.get() && this->mouseDownX &&
this->getXRect().contains(event->pos())) {
this->mouseDownX = false;
this->notebook->removePage(this->page);
@ -188,7 +182,7 @@ NotebookTab::mouseMoveEvent(QMouseEvent *event)
bool overX = this->getXRect().contains(event->pos());
if (overX != this->mouseOverX) {
this->mouseOverX = overX;
this->mouseOverX = overX && !Settings::getInstance().hideTabX.get();
this->update();
}

View file

@ -4,6 +4,8 @@
#include <QPropertyAnimation>
#include <QWidget>
#include <boost/property_tree/ptree.hpp>
#include <boost/signals2.hpp>
#include <boost/signals2/connection.hpp>
namespace chatterino {
namespace widgets {
@ -76,6 +78,13 @@ public:
return QRect(posAnimationDesired, this->size());
}
void
hideTabXChanged(bool)
{
calcSize();
update();
}
protected:
void paintEvent(QPaintEvent *) override;
@ -89,6 +98,8 @@ protected:
void mouseMoveEvent(QMouseEvent *event) override;
private:
boost::signals2::connection hideXConnection;
QPropertyAnimation posAnimation;
bool posAnimated;
QPoint posAnimationDesired;
@ -111,14 +122,6 @@ private:
return QRect(this->width() - 20, 4, 16, 16);
}
private slots:
void
hideTabXChanged(bool)
{
calcSize();
update();
}
public:
void load(const boost::property_tree::ptree &tree);
boost::property_tree::ptree save();

View file

@ -76,10 +76,19 @@ SettingsDialog::addTabs()
auto combo = new QComboBox();
auto slider = new QSlider(Qt::Horizontal);
auto font = new QPushButton("select");
auto compactTabs = createCheckbox("Hide tab X", settings.hideTabX);
auto hidePreferencesButton =
createCheckbox("Hide preferences button (ctrl+p to show)",
settings.hidePreferencesButton);
auto hideUserButton =
createCheckbox("Hide user button", settings.hideUserButton);
form->addRow("Theme:", combo);
form->addRow("Theme color:", slider);
form->addRow("Font:", font);
form->addRow("", compactTabs);
form->addRow("", hidePreferencesButton);
form->addRow("", hideUserButton);
// theme
combo->addItem("White");