mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
added auto resizing input & settings
This commit is contained in:
parent
d215bd58b0
commit
a114bd1204
12 changed files with 108 additions and 9 deletions
|
@ -111,7 +111,8 @@ HEADERS += account.h \
|
|||
settings/boolsetting.h \
|
||||
settings/stringsetting.h \
|
||||
settings/intsetting.h \
|
||||
settings/floatsetting.h
|
||||
settings/floatsetting.h \
|
||||
widgets/resizingtextedit.h
|
||||
|
||||
PRECOMPILED_HEADER =
|
||||
|
||||
|
|
|
@ -70,6 +70,10 @@ ColorScheme::setColors(float hue, float multiplyer)
|
|||
// for (int i = 0; i < LOOKUP_COLOR_COUNT; i++) {
|
||||
// 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,
|
||||
|
|
|
@ -11,6 +11,8 @@ class ColorScheme
|
|||
public:
|
||||
bool IsLightTheme;
|
||||
|
||||
QString InputStyleSheet;
|
||||
|
||||
QColor SystemMessageColor;
|
||||
|
||||
QColor DropPreviewBackground;
|
||||
|
|
|
@ -26,7 +26,11 @@ public:
|
|||
void
|
||||
set(bool value)
|
||||
{
|
||||
if (this->value != value) {
|
||||
this->value = value;
|
||||
|
||||
emit valueChanged(value);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -39,6 +43,9 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
signals:
|
||||
void valueChanged(bool value);
|
||||
|
||||
private:
|
||||
bool value;
|
||||
bool defaultValue;
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
|
||||
namespace chatterino {
|
||||
namespace settings {
|
||||
class BoolSetting : public Setting
|
||||
class IntSetting : public Setting
|
||||
{
|
||||
public:
|
||||
BoolSetting(const QString &name, int defaultValue)
|
||||
IntSetting(const QString &name, int defaultValue)
|
||||
: Setting(name)
|
||||
, value(defaultValue)
|
||||
, defaultValue(defaultValue)
|
||||
|
|
|
@ -31,6 +31,7 @@ BoolSetting Settings::enableGifAnimations("", true);
|
|||
BoolSetting Settings::enableGifs("", true);
|
||||
BoolSetting Settings::inlineWhispers("", true);
|
||||
BoolSetting Settings::windowTopMost("", true);
|
||||
BoolSetting Settings::compactTabs("", false);
|
||||
|
||||
QSettings Settings::settings(
|
||||
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation),
|
||||
|
|
|
@ -71,6 +71,7 @@ private:
|
|||
settingsItems.push_back(&enableGifs);
|
||||
settingsItems.push_back(&inlineWhispers);
|
||||
settingsItems.push_back(&windowTopMost);
|
||||
settingsItems.push_back(&compactTabs);
|
||||
}
|
||||
|
||||
static QSettings settings;
|
||||
|
@ -215,6 +216,11 @@ public:
|
|||
{
|
||||
return Settings::windowTopMost;
|
||||
}
|
||||
static BoolSetting
|
||||
getCompactTabs()
|
||||
{
|
||||
return Settings::compactTabs;
|
||||
}
|
||||
|
||||
private:
|
||||
static StringSetting theme;
|
||||
|
@ -242,6 +248,7 @@ private:
|
|||
static BoolSetting enableGifs;
|
||||
static BoolSetting inlineWhispers;
|
||||
static BoolSetting windowTopMost;
|
||||
static BoolSetting compactTabs;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,13 @@ public:
|
|||
const QString &
|
||||
set(const QString &value)
|
||||
{
|
||||
return (this->value = value);
|
||||
this->value = value;
|
||||
|
||||
QString tmp = value;
|
||||
|
||||
emit valueChanged(tmp);
|
||||
|
||||
return this->value;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -40,6 +46,9 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
signals:
|
||||
void valueChanged(const QString &value);
|
||||
|
||||
private:
|
||||
QString value;
|
||||
QString defaultValue;
|
||||
|
|
|
@ -23,8 +23,12 @@ ChatWidget::ChatWidget(QWidget *parent)
|
|||
this->vbox.setSpacing(0);
|
||||
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(&view);
|
||||
this->vbox.addWidget(&view, 1);
|
||||
this->vbox.addWidget(&input);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,9 +7,16 @@ namespace chatterino {
|
|||
namespace widgets {
|
||||
|
||||
ChatWidgetInput::ChatWidgetInput()
|
||||
: edit(this)
|
||||
: hbox()
|
||||
, edit()
|
||||
{
|
||||
setFixedHeight(38);
|
||||
this->setLayout(&hbox);
|
||||
|
||||
this->setMaximumHeight(100);
|
||||
|
||||
this->hbox.addWidget(&edit);
|
||||
|
||||
edit.setStyleSheet(ColorScheme::instance().InputStyleSheet);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
#ifndef CHATWIDGETINPUT_H
|
||||
#define CHATWIDGETINPUT_H
|
||||
|
||||
#include "resizingtextedit.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QPaintEvent>
|
||||
#include <QTextEdit>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
|
||||
namespace chatterino {
|
||||
|
@ -19,7 +24,8 @@ protected:
|
|||
void paintEvent(QPaintEvent *);
|
||||
|
||||
private:
|
||||
QTextEdit edit;
|
||||
QHBoxLayout hbox;
|
||||
ResizingTextEdit edit;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
51
widgets/resizingtextedit.h
Normal file
51
widgets/resizingtextedit.h
Normal 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
|
Loading…
Reference in a new issue