/* Marcion
Copyright (C) 2009-2013 Milan Konvicka
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 2 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.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
#include "mimagewidget.h"
#include "ui_mimagewidget.h"
MImageWidget::MImageWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::MImageWidget),
bgr()
{
ui->setupUi(this);
ui->ccPen->init("white",m_sett()->imgSelBorderColor().name(),tr("border color"),CTextColorChooser::Background);
ui->ccFill->init("white",m_sett()->imgSelFillColor().name(),tr("fill color"),CTextColorChooser::Background);
ui->spnBorder->setValue(m_sett()->imgSelBorderWidth());
ui->spnOpacity->setValue(m_sett()->imgSelFillOpacity());
bgr.addButton(ui->btMove,1);
bgr.addButton(ui->btSelect,2);
ui->gbSett->setVisible(false);
}
MImageWidget::~MImageWidget()
{
delete ui;
}
CMImage * MImageWidget::drawarea()
{
return ui->gwArea;
}
void MImageWidget::on_gwArea_positionChanged(QPointF pos)
{
QSize _csize(ui->gwArea->currentPageSize().toSize());
if(_csize.isValid())
{
int x((int)pos.x()),y((int)pos.y());
if(x<0||x>_csize.width())
ui->lblPosX->setText("N/A");
else
ui->lblPosX->setText(QString::number(x));
if(y<0||y>_csize.height())
ui->lblPosY->setText("N/A");
else
ui->lblPosY->setText(QString::number(y));
}
else
{
ui->lblPosX->setText("N/A");
ui->lblPosY->setText("N/A");
}
}
void MImageWidget::on_btImageAction_clicked(bool checked)
{
if(checked)
ui->gwArea->showPopupOnButton(ui->btImageAction);
}
void MImageWidget::on_btMove_clicked(bool checked)
{
if(checked)
ui->gwArea->setMouseMode(CMImage::Move,false);
}
void MImageWidget::on_btSelect_clicked(bool checked)
{
if(checked)
ui->gwArea->setMouseMode(CMImage::Select,false);
}
void MImageWidget::on_gwArea_mouseModeChanged(int mouse_mode)
{
switch(mouse_mode)
{
case CMImage::Move :
ui->btMove->setChecked(true);
break;
case CMImage::Select :
ui->btSelect->setChecked(true);
break;
}
}
void MImageWidget::on_btSett_clicked(bool checked)
{
ui->gbSett->setVisible(checked);
ui->gwArea->setSettingsState(checked);
}
void MImageWidget::on_gwArea_settingsActivated(bool visible)
{
ui->gbSett->setVisible(visible);
ui->btSett->setChecked(visible);
}
void MImageWidget::on_spnBorder_valueChanged(int value)
{
ui->gwArea->setSelectionBorderWidth(value);
}
void MImageWidget::on_spnOpacity_valueChanged(int value)
{
QColor color(ui->ccFill->bgC());
color.setAlpha(2.55*value);
ui->gwArea->setSelectionFillColor(color);
}
void MImageWidget::on_ccPen_bgColorSelected(QColor color)
{
ui->gwArea->setSelectionBorderColor(color);
}
void MImageWidget::on_ccFill_bgColorSelected(QColor color)
{
color.setAlpha(2.55*ui->spnOpacity->value());
ui->gwArea->setSelectionFillColor(color);
}
void MImageWidget::keyPressEvent ( QKeyEvent * e )
{
e->ignore();
ui->gwArea->keyPressEvent(e);
if(!e->isAccepted())
QWidget::keyPressEvent(e);
}