/****************************************************************************
**
** Copyright (C) 2019 Minnesota Department of Transportation
** Office of Materials & Road Research
** 1400 Gervais Avenue
** Saint Paul, Minnesota 55109-2044
** USA
** http://www.dot.state.mn.us/materials/pvmtdesign/software.html
**
**
** $QT_BEGIN_LICENSE:GPL$
**
** This program 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.
**
** This program 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.
**
** If you did not receive a copy of the GNU General Public License
** see http://www.gnu.org/licenses
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "notesdlg.h"
#include "ui_notesdlg.h"
#include "calc.h"
#include "globals.h"
#include "mnpave.h"

NotesDlg::NotesDlg(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::NotesDlg)
{
    ui->setupUi(this);
}

NotesDlg::~NotesDlg()
{
    delete ui;
}

void NotesDlg::resizeEvent(QResizeEvent *e)
{// proportional widget resizing
    int ew = e->size().width(); // MainWindow
    int eh = e->size().height();
    int nw, nh;
    double ht;
    nw = LANDW/2;
    nh = LANDH/2;
    // resize widgets
    QRect wRect[2];    // Holds original geometries for widgets
    wRect[0] = QRect(10,205,300,32); // buttonBox
    wRect[1] = QRect(10,10,300,190); // notesEdit
    ui->buttonBox->setGeometry(wRect[0].x()*ew/nw, wRect[0].y()*eh/nh, wRect[0].width()*ew/nw, wRect[0].height()*eh/nh);
    ui->notesEdit->setGeometry(wRect[1].x()*ew/nw, wRect[1].y()*eh/nh, wRect[1].width()*ew/nw, wRect[1].height()*eh/nh);

    // test height/width ratio
    if((double) eh / (double) ew < 0.75) ht = (double) ew * 0.75 / (double) nw * 8.; // new font size
    else ht = (double) eh / (double) nh * 8.; // new font size
    eh = nint(ht); // adjust for half-size dialog

    QFont newFont = ui->buttonBox->font();
    if(eh != newFont.pointSize())
    {
        newFont.setPointSize(eh);
        ui->buttonBox->setFont(newFont);
        ui->notesEdit->setFont(newFont);
    }
}

void NotesDlg::loadText()
{
    ui->notesEdit->setPlainText(tNotes);
    ui->notesEdit->setFocus();
}

void NotesDlg::on_notesEdit_textChanged()
{
    tNotes = ui->notesEdit->toPlainText();
}
