Subversion Repositories OpenInventory

Compare Revisions

Ignore whitespace Rev 179 → Rev 180

/trunk/DBViewer/iconform.ui
New file
0,0 → 1,74
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>IconForm</class>
<widget class="QWidget" name="IconForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>133</width>
<height>69</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>31</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="pic.qrc">
<normaloff>:/Open.png</normaloff>:/Open.png</iconset>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>0</x>
<y>40</y>
<width>31</width>
<height>30</height>
</rect>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="pic.qrc">
<normaloff>:/Delete.png</normaloff>:/Delete.png</iconset>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>30</x>
<y>0</y>
<width>101</width>
<height>71</height>
</rect>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap>pc.png</pixmap>
</property>
</widget>
</widget>
<resources>
<include location="pic.qrc"/>
</resources>
<connections/>
</ui>
/trunk/DBViewer/delegate.cpp
403,3 → 403,173
// done
painter->restore();
}
 
 
 
 
 
 
IconDelegate::IconDelegate( QObject * parent ) : QItemDelegate(parent)
{
}
 
 
 
 
 
QWidget *IconDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/* option */,
const QModelIndex & /* index */) const
{
 
IconForm *editor = new IconForm(parent);
 
return editor;
 
}
 
 
 
 
void IconDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
 
 
const QAbstractItemModel * model = index.model();
IconForm *icnFrm = static_cast<IconForm*>(editor);
QVariant currentImage = model->data(index,0);
QByteArray bytes = currentImage.toByteArray();
if (currentImage.isValid()) {
m_pxPicture.loadFromData(bytes);
}
else {
//QItemDelegate::paint(painter, option, index);
 
 
return;
}
icnFrm->setPixmap(m_pxPicture);
// tblView->setRowHeight(index.row(), icnFrm->geometry().height());
}
 
 
 
 
void IconDelegate::setModelData(
QWidget *editor,
QAbstractItemModel *model,
const QModelIndex& index) const {
IconForm *icnFrm = static_cast<IconForm*>(editor);
if (!(icnFrm->dataIsChanged())) return;
 
m_pxPicture = icnFrm->pixmap();
QImage currentImage = m_pxPicture.toImage();
QByteArray bytes;
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
currentImage.save(&buffer, "PNG");
 
 
 
 
model->setData(index, QVariant (bytes), Qt::EditRole);
 
// int widht = m_pxPicture.width();
// int heigh = m_pxPicture.height();
// tblView->setRowHeight(index.row(), heigh + 10);
// model->submitAll();
 
 
 
 
// model->setData(index, value);
}
 
 
 
void IconDelegate::updateEditorGeometry(
QWidget *editor,
const QStyleOptionViewItem &option,
const QModelIndex& /* index */) const {
 
 
// QRect r(option.rect.x() + option.rect.width()/2 - 7, option.rect.y() + option.rect.height()/2 - 7, 150, 100);
// editor->setGeometry(r);
 
editor->setGeometry(option.rect);
}
 
 
 
 
void IconDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
 
 
m_pxPicture.fill( QColor(Qt::white) );
 
const QAbstractItemModel * model = index.model();
QString sFileName = model->data( index, Qt::DisplayRole ).toString();
 
QVariant currentImage = model->data(index,0);
 
 
QByteArray bytes = currentImage.toByteArray();
// QImage image;
// image.loadFromData(bytes);
 
 
if (currentImage.isValid()) {
m_pxPicture.loadFromData(bytes);
 
}
else {
//QItemDelegate::paint(painter, option, index);
return;
}
 
 
 
 
 
/*
 
if ( !sFileName.isEmpty() )
m_pxPicture.load( sFileName );
else {
//QItemDelegate::paint(painter, option, index);
return;
}
*/
 
 
QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ?
((option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive ) :
QPalette::Disabled;
 
if (option.state & QStyle::State_Selected)
 
 
painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight));
 
int nX = option.rect.x() + ( ( option.rect.width() - m_pxPicture.rect().width() ) / 2 );
int nY = option.rect.y() + ( ( option.rect.height() - m_pxPicture.rect().height() ) / 2 );
painter->drawPixmap( nX, nY, m_pxPicture );
 
 
// drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves
 
/*
QPen pen = painter->pen();
painter->setPen(option.palette.color(QPalette::Mid));
painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
painter->setPen(pen);
*/
}
 
 
void IconDelegate::setTableView(QTableView* table){
tblView = table;
}
/trunk/DBViewer/iconform.cpp
New file
0,0 → 1,64
#include "iconform.h"
#include "ui_iconform.h"
#include "mainwindow.h"
 
 
IconForm::IconForm(QWidget *parent) :
QWidget(parent),
ui(new Ui::IconForm)
{
ui->setupUi(this);
IconForm::fdataIsChanged = false;
}
 
IconForm::~IconForm()
{
delete ui;
}
 
void IconForm::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
 
 
void IconForm::on_pushButton_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Ïîìåíÿòü èêîíêó"
 
QString fileName;
fileName = QFileDialog::getOpenFileName(this,
tr("Open Image"), "", tr("Image Files (*.png *.jpg *.bmp)"));
 
if (fileName.isEmpty()) return;
Pixmap.load(fileName);
 
ui->label->setPixmap(Pixmap);
IconForm::fdataIsChanged = true;
// IconForm::close();
}
 
 
void IconForm::setPixmap (QPixmap newPixmap){
Pixmap = newPixmap;
ui->label->setPixmap(Pixmap);
 
}
 
 
QPixmap IconForm::pixmap (){
return Pixmap;
}
 
 
bool IconForm::dataIsChanged(){
return IconForm::fdataIsChanged;
}
 
 
// void IconForm::clearPixmap(){}
/trunk/DBViewer/delegate.h
11,6 → 11,9
#include <QtGui>
#include <QSqlDatabase>
#include <QMessageBox>
 
#include "iconform.h"
 
//#include <QMainWindow>
//! [0]
class SpinBoxDelegate : public QItemDelegate
89,9 → 92,44
};
 
 
class IconDelegate : public QItemDelegate
{
mutable QPixmap m_pxPicture;
private:
QTableView *tblView;
 
public:
IconDelegate ( QObject *parent );
 
QWidget *createEditor(
QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index) const;
 
void setEditorData(QWidget *editor,
const QModelIndex &index) const;
 
void setModelData(QWidget *editor,
QAbstractItemModel *model,
const QModelIndex &index) const;
 
 
void updateEditorGeometry(
QWidget *editor,
const QStyleOptionViewItem &option,
const QModelIndex &index) const;
 
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
 
void setTableView(QTableView* table);
 
 
//QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
};
 
 
 
class TimeEditDelegate : public QItemDelegate
{
Q_OBJECT
/trunk/DBViewer/iconform.h
New file
0,0 → 1,33
#ifndef ICONFORM_H
#define ICONFORM_H
 
#include <QWidget>
 
namespace Ui {
class IconForm;
}
 
class IconForm : public QWidget {
Q_OBJECT
public:
IconForm(QWidget *parent = 0);
~IconForm();
void setPixmap (QPixmap newPixmap);
// void clearPixmap();
QPixmap pixmap ();
bool dataIsChanged();
protected:
void changeEvent(QEvent *e);
 
private:
Ui::IconForm *ui;
QPixmap Pixmap;
bool fdataIsChanged;
private slots:
 
void on_pushButton_clicked(); // îáðàáîò÷èê íàæàòèÿ êíîïêè "Ïîìåíÿòü èêîíêó"
 
 
};
 
#endif // ICONFORM_H
/trunk/DBViewer/DBViewer.pro
18,11 → 18,14
database.cpp \
delegate.cpp \
mymodel.cpp \
settingform.cpp
settingform.cpp \
iconform.cpp
HEADERS += mainwindow.h \
delegate.h \
mymodel.h \
settingform.h
settingform.h \
iconform.h
FORMS += mainwindow.ui \
settingform.ui
settingform.ui \
iconform.ui
RESOURCES += dbviewer.qrc