/* Marcion
Copyright (C) 2009 - 2011 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; version 2 of the License.
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 */
#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"),true);
ui->ccFill->init("white",m_sett()->imgSelFillColor().name(),tr("fill color"),true);
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)
{
ui->lblPosX->setText(QString::number(pos.x()));
ui->lblPosY->setText(QString::number(pos.y()));
}
void MImageWidget::on_btImageAction_clicked()
{
ui->gwArea->showPopupOnButton(ui->btImageAction->mapToGlobal(QPoint(0,0)));
}
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);
}