Add ResizableTextEdit

This commit is contained in:
Jonas Kvinge 2022-06-05 04:39:06 +02:00
parent 32ac02007b
commit 683991b1c9
4 changed files with 88 additions and 0 deletions

2
debian/copyright vendored
View File

@ -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 <jonas@jkvinge.net>
License: GPL-3+

View File

@ -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

View File

@ -0,0 +1,45 @@
/*
* Strawberry Music Player
* Copyright 2022, Jonas Kvinge <jonas@jkvinge.net>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#include <QTextEdit>
#include <QResizeEvent>
#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);
}

View File

@ -0,0 +1,39 @@
/*
* Strawberry Music Player
* Copyright 2022, Jonas Kvinge <jonas@jkvinge.net>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#ifndef RESIZABLETEXTEDIT_H
#define RESIZABLETEXTEDIT_H
#include <QTextEdit>
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