File indexing completed on 2024-05-12 15:28:20

0001 /***************************************************************************
0002     File                 : ResizableTextEdit.h
0003     Project              : LabPlot
0004     Description          : Extended TextEdit to allow the manual resize by the user
0005     --------------------------------------------------------------------
0006     Copyright            : (C) 2018 Alexander Semke (alexander.semke@web.de)
0007 
0008  ***************************************************************************/
0009 
0010 /***************************************************************************
0011  *                                                                         *
0012  *  This program is free software; you can redistribute it and/or modify   *
0013  *  it under the terms of the GNU General Public License as published by   *
0014  *  the Free Software Foundation; either version 2 of the License, or      *
0015  *  (at your option) any later version.                                    *
0016  *                                                                         *
0017  *  This program is distributed in the hope that it will be useful,        *
0018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
0019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
0020  *  GNU General Public License for more details.                           *
0021  *                                                                         *
0022  *   You should have received a copy of the GNU General Public License     *
0023  *   along with this program; if not, write to the Free Software           *
0024  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
0025  *   Boston, MA  02110-1301  USA                                           *
0026  *                                                                         *
0027  ***************************************************************************/
0028 #ifndef RESIZABLETEXTEDIT_H
0029 #define RESIZABLETEXTEDIT_H
0030 
0031 #include <QTextEdit>
0032 
0033 class ResizableTextEdit;
0034 
0035 class GrabBar : public QWidget {
0036     Q_OBJECT
0037 
0038 public:
0039     GrabBar(ResizableTextEdit*, bool vertResizeOnly);
0040     QSize sizeHint() const override;
0041 
0042 protected:
0043     void paintEvent(QPaintEvent*) override;
0044     void mousePressEvent(QMouseEvent*) override;
0045     void mouseReleaseEvent(QMouseEvent*) override;
0046     void mouseMoveEvent(QMouseEvent*) override;
0047     void enterEvent(QEvent*) override;
0048     void leaveEvent(QEvent*) override;
0049 
0050 private:
0051     ResizableTextEdit* m_parent;
0052     QPoint m_pos;
0053     bool m_pressed{false};
0054     bool m_vertResizeOnly;
0055 };
0056 
0057 class ResizableTextEdit : public QTextEdit {
0058     Q_OBJECT
0059 public:
0060     explicit ResizableTextEdit(QWidget*, bool vertResizeOnly = true);
0061     void addSize(QSize);
0062     QSize sizeHint() const override;
0063 
0064 protected:
0065     void resizeEvent(QResizeEvent*) override;
0066 
0067 private:
0068     GrabBar* m_grabBar;
0069     QSize m_size;
0070     bool m_vertResizeOnly;
0071 };
0072 
0073 #endif