added auto resizing input & settings

This commit is contained in:
fourtf 2017-01-21 05:14:27 +01:00
parent d215bd58b0
commit a114bd1204
12 changed files with 108 additions and 9 deletions

View file

@ -111,7 +111,8 @@ HEADERS += account.h \
settings/boolsetting.h \ settings/boolsetting.h \
settings/stringsetting.h \ settings/stringsetting.h \
settings/intsetting.h \ settings/intsetting.h \
settings/floatsetting.h settings/floatsetting.h \
widgets/resizingtextedit.h
PRECOMPILED_HEADER = PRECOMPILED_HEADER =

View file

@ -70,6 +70,10 @@ ColorScheme::setColors(float hue, float multiplyer)
// for (int i = 0; i < LOOKUP_COLOR_COUNT; i++) { // for (int i = 0; i < LOOKUP_COLOR_COUNT; i++) {
// qInfo(QString::number(this->middleLookupTable[i]).toStdString().c_str()); // qInfo(QString::number(this->middleLookupTable[i]).toStdString().c_str());
// } // }
InputStyleSheet = "background:" + ChatInputBackground.name() + ";" +
"border:" + TabSelectedBackground.name() + ";" +
"color:" + Text.name();
} }
void ColorScheme::fillLookupTableValues(qreal (&array)[360], qreal from, void ColorScheme::fillLookupTableValues(qreal (&array)[360], qreal from,

View file

@ -11,6 +11,8 @@ class ColorScheme
public: public:
bool IsLightTheme; bool IsLightTheme;
QString InputStyleSheet;
QColor SystemMessageColor; QColor SystemMessageColor;
QColor DropPreviewBackground; QColor DropPreviewBackground;

View file

@ -26,7 +26,11 @@ public:
void void
set(bool value) set(bool value)
{ {
if (this->value != value) {
this->value = value; this->value = value;
emit valueChanged(value);
}
} }
void void
@ -39,6 +43,9 @@ public:
{ {
} }
signals:
void valueChanged(bool value);
private: private:
bool value; bool value;
bool defaultValue; bool defaultValue;

View file

@ -7,10 +7,10 @@
namespace chatterino { namespace chatterino {
namespace settings { namespace settings {
class BoolSetting : public Setting class IntSetting : public Setting
{ {
public: public:
BoolSetting(const QString &name, int defaultValue) IntSetting(const QString &name, int defaultValue)
: Setting(name) : Setting(name)
, value(defaultValue) , value(defaultValue)
, defaultValue(defaultValue) , defaultValue(defaultValue)

View file

@ -31,6 +31,7 @@ BoolSetting Settings::enableGifAnimations("", true);
BoolSetting Settings::enableGifs("", true); BoolSetting Settings::enableGifs("", true);
BoolSetting Settings::inlineWhispers("", true); BoolSetting Settings::inlineWhispers("", true);
BoolSetting Settings::windowTopMost("", true); BoolSetting Settings::windowTopMost("", true);
BoolSetting Settings::compactTabs("", false);
QSettings Settings::settings( QSettings Settings::settings(
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation), QStandardPaths::writableLocation(QStandardPaths::AppDataLocation),

View file

@ -71,6 +71,7 @@ private:
settingsItems.push_back(&enableGifs); settingsItems.push_back(&enableGifs);
settingsItems.push_back(&inlineWhispers); settingsItems.push_back(&inlineWhispers);
settingsItems.push_back(&windowTopMost); settingsItems.push_back(&windowTopMost);
settingsItems.push_back(&compactTabs);
} }
static QSettings settings; static QSettings settings;
@ -215,6 +216,11 @@ public:
{ {
return Settings::windowTopMost; return Settings::windowTopMost;
} }
static BoolSetting
getCompactTabs()
{
return Settings::compactTabs;
}
private: private:
static StringSetting theme; static StringSetting theme;
@ -242,6 +248,7 @@ private:
static BoolSetting enableGifs; static BoolSetting enableGifs;
static BoolSetting inlineWhispers; static BoolSetting inlineWhispers;
static BoolSetting windowTopMost; static BoolSetting windowTopMost;
static BoolSetting compactTabs;
}; };
} }
} }

View file

@ -27,7 +27,13 @@ public:
const QString & const QString &
set(const QString &value) set(const QString &value)
{ {
return (this->value = value); this->value = value;
QString tmp = value;
emit valueChanged(tmp);
return this->value;
} }
void void
@ -40,6 +46,9 @@ public:
{ {
} }
signals:
void valueChanged(const QString &value);
private: private:
QString value; QString value;
QString defaultValue; QString defaultValue;

View file

@ -23,8 +23,12 @@ ChatWidget::ChatWidget(QWidget *parent)
this->vbox.setSpacing(0); this->vbox.setSpacing(0);
this->vbox.setMargin(1); this->vbox.setMargin(1);
// header.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
// view.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
// input.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
this->vbox.addWidget(&header); this->vbox.addWidget(&header);
this->vbox.addWidget(&view); this->vbox.addWidget(&view, 1);
this->vbox.addWidget(&input); this->vbox.addWidget(&input);
} }

View file

@ -7,9 +7,16 @@ namespace chatterino {
namespace widgets { namespace widgets {
ChatWidgetInput::ChatWidgetInput() ChatWidgetInput::ChatWidgetInput()
: edit(this) : hbox()
, edit()
{ {
setFixedHeight(38); this->setLayout(&hbox);
this->setMaximumHeight(100);
this->hbox.addWidget(&edit);
edit.setStyleSheet(ColorScheme::instance().InputStyleSheet);
} }
void void

View file

@ -1,8 +1,13 @@
#ifndef CHATWIDGETINPUT_H #ifndef CHATWIDGETINPUT_H
#define CHATWIDGETINPUT_H #define CHATWIDGETINPUT_H
#include "resizingtextedit.h"
#include <QHBoxLayout>
#include <QLineEdit>
#include <QPaintEvent> #include <QPaintEvent>
#include <QTextEdit> #include <QTextEdit>
#include <QVBoxLayout>
#include <QWidget> #include <QWidget>
namespace chatterino { namespace chatterino {
@ -19,7 +24,8 @@ protected:
void paintEvent(QPaintEvent *); void paintEvent(QPaintEvent *);
private: private:
QTextEdit edit; QHBoxLayout hbox;
ResizingTextEdit edit;
}; };
} }
} }

View file

@ -0,0 +1,51 @@
#ifndef RESIZINGTEXTEDIT_H
#define RESIZINGTEXTEDIT_H
#include <QTextEdit>
class ResizingTextEdit : public QTextEdit
{
public:
ResizingTextEdit()
{
auto sizePolicy = this->sizePolicy();
sizePolicy.setHeightForWidth(true);
sizePolicy.setVerticalPolicy(QSizePolicy::Preferred);
this->setSizePolicy(sizePolicy);
QObject::connect(this, &QTextEdit::textChanged, this, &updateGeometry);
}
QSize
sizeHint() const override
{
return QSize(this->width(), this->heightForWidth(this->width()));
}
bool
hasHeightForWidth() const override
{
return true;
}
protected:
int
heightForWidth(int w) const override
{
auto margins = this->contentsMargins();
int documentWidth;
if (w >= margins.left() + margins.right()) {
documentWidth = w - margins.left() - margins.right();
} else {
documentWidth = 0;
}
auto document = this->document()->clone();
return margins.top() + document->size().height() + margins.bottom() + 2;
}
};
#endif // RESIZINGTEXTEDIT_H