File indexing completed on 2024-05-12 15:27:38

0001 /***************************************************************************
0002     File                 : NotesView.cpp
0003     Project              : LabPlot
0004     Description          : Notes View for taking notes
0005     --------------------------------------------------------------------
0006     Copyright            : (C) 2016-2016 Garvit Khatri (garvitdelhi@gmail.com)
0007     Copyright            : (C) 2016 Alexander Semke (alexander.semke@web.de)
0008 
0009  ***************************************************************************/
0010 
0011 /***************************************************************************
0012  *                                                                         *
0013  *  This program is free software; you can redistribute it and/or modify   *
0014  *  it under the terms of the GNU General Public License as published by   *
0015  *  the Free Software Foundation; either version 2 of the License, or      *
0016  *  (at your option) any later version.                                    *
0017  *                                                                         *
0018  *  This program is distributed in the hope that it will be useful,        *
0019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
0020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
0021  *  GNU General Public License for more details.                           *
0022  *                                                                         *
0023  *   You should have received a copy of the GNU General Public License     *
0024  *   along with this program; if not, write to the Free Software           *
0025  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
0026  *   Boston, MA  02110-1301  USA                                           *
0027  *                                                                         *
0028  ***************************************************************************/
0029 
0030 #include "NoteView.h"
0031 #include "backend/note/Note.h"
0032 
0033 #include <QHBoxLayout>
0034 #include <QPrinter>
0035 #include <QTextEdit>
0036 
0037 NoteView::NoteView(Note* notes) : m_notes(notes) {
0038     auto* layout = new QHBoxLayout(this);
0039     layout->setContentsMargins(0, 0, 0, 0);
0040 
0041     m_textEdit = new QTextEdit(this);
0042 
0043     QPalette palette = m_textEdit->palette();
0044 
0045     palette.setColor(QPalette::Base, m_notes->backgroundColor());
0046     palette.setColor(QPalette::Text, m_notes->textColor());
0047 
0048     m_textEdit->setPalette(palette);
0049     m_textEdit->setFont(m_notes->textFont());
0050     m_textEdit->setText(m_notes->note());
0051 
0052     layout->addWidget(m_textEdit);
0053 
0054     connect(m_notes, &Note::backgroundColorChanged, this, &NoteView::backgroundColorChanged);
0055     connect(m_notes, &Note::textColorChanged, this, &NoteView::textColorChanged);
0056     connect(m_notes, &Note::textFontChanged, this, &NoteView::textFontChanged);
0057     connect(m_textEdit, &QTextEdit::textChanged, this, &NoteView::textChanged);
0058 }
0059 
0060 void NoteView::print(QPrinter* printer) const {
0061     m_textEdit->print(printer);
0062 }
0063 
0064 void NoteView::textChanged() {
0065     m_notes->setNote(m_textEdit->toPlainText());
0066 }
0067 
0068 void NoteView::backgroundColorChanged(QColor color) {
0069     QPalette palette = m_textEdit->palette();
0070     palette.setColor(QPalette::Base, color);
0071     m_textEdit->setPalette(palette);
0072 }
0073 
0074 void NoteView::textFontChanged(const QFont& font) {
0075     m_textEdit->setFont(font);
0076 }
0077 
0078 void NoteView::textColorChanged(QColor color) {
0079     QPalette palette = m_textEdit->palette();
0080     palette.setColor(QPalette::Text, color);
0081     m_textEdit->setPalette(palette);
0082 }