diff --git a/debian/copyright b/debian/copyright index 45b23116..112c0ba9 100644 --- a/debian/copyright +++ b/debian/copyright @@ -96,6 +96,8 @@ Files: src/core/main.h ext/libstrawberry-tagreader/tagreadertagparser.cpp ext/libstrawberry-tagreader/tagreadertagparser.h ext/macdeploycheck/* + widgets/resizabletextedit.cpp + widgets/resizabletextedit.h Copyright: 2012-2014, 2017-2022, Jonas Kvinge License: GPL-3+ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e24593a5..f4f57ae9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -212,6 +212,7 @@ set(SOURCES widgets/tracksliderslider.cpp widgets/loginstatewidget.cpp widgets/ratingwidget.cpp + widgets/resizabletextedit.cpp osd/osdbase.cpp osd/osdpretty.cpp @@ -445,6 +446,7 @@ set(HEADERS widgets/qsearchfield.h widgets/ratingwidget.h widgets/forcescrollperpixel.h + widgets/resizabletextedit.h osd/osdbase.h osd/osdpretty.h diff --git a/src/widgets/resizabletextedit.cpp b/src/widgets/resizabletextedit.cpp new file mode 100644 index 00000000..f48526e5 --- /dev/null +++ b/src/widgets/resizabletextedit.cpp @@ -0,0 +1,45 @@ +/* + * Strawberry Music Player + * Copyright 2022, Jonas Kvinge + * + * Strawberry is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Strawberry is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Strawberry. If not, see . + * + */ + +#include +#include + +#include "resizabletextedit.h" + +ResizableTextEdit::ResizableTextEdit(QWidget *parent) + : QTextEdit(parent) { + + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + +} + +QSize ResizableTextEdit::sizeHint() const { + + return QSize(std::max(QTextEdit::sizeHint().width(), 10), std::max(document()->size().toSize().height(), 10)); + +} + +void ResizableTextEdit::resizeEvent(QResizeEvent *e) { + + updateGeometry(); + QTextEdit::resizeEvent(e); + +} diff --git a/src/widgets/resizabletextedit.h b/src/widgets/resizabletextedit.h new file mode 100644 index 00000000..551821b3 --- /dev/null +++ b/src/widgets/resizabletextedit.h @@ -0,0 +1,39 @@ +/* + * Strawberry Music Player + * Copyright 2022, Jonas Kvinge + * + * Strawberry is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Strawberry is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Strawberry. If not, see . + * + */ + +#ifndef RESIZABLETEXTEDIT_H +#define RESIZABLETEXTEDIT_H + +#include + +class QResizeEvent; + +class ResizableTextEdit: public QTextEdit { + + public: + explicit ResizableTextEdit(QWidget *parent = nullptr); + + virtual QSize sizeHint() const override; + +protected: + virtual void resizeEvent(QResizeEvent *event) override; + +}; + +#endif // RESIZABLETEXTEDIT_H