00001 #include <QWidget>
00002 #include <QTextEdit>
00003 #include <QtDebug>
00004 #include <QSizePolicy>
00005 #include <QIcon>
00006 #include <QMessageBox>
00007 #include <QTextDocumentFragment>
00008
00009 #include "editrecord.h"
00010 #include "main.h"
00011
00012 editrecord::editrecord( QWidget * parent, Qt::WFlags f) : QDialog(parent, f)
00013 {
00014 setup_ui();
00015 setup_signals();
00016 assembly();
00017 }
00018
00019 editrecord::~editrecord()
00020 {
00021
00022 }
00023
00024
00025 void editrecord::setup_ui(void)
00026 {
00027
00028 infofield=new infofieldenter();
00029
00030
00031 buttonbox=new QDialogButtonBox();
00032 buttonbox->setOrientation(Qt::Horizontal);
00033 buttonbox->setStandardButtons(QDialogButtonBox::Ok|QDialogButtonBox::NoButton|QDialogButtonBox::Cancel);
00034 }
00035
00036 void editrecord::setup_signals(void)
00037 {
00038 connect(buttonbox, SIGNAL(accepted()), this, SLOT(ok_click(void)));
00039 connect(buttonbox, SIGNAL(rejected()), this, SLOT(reject()));
00040 }
00041
00042 void editrecord::assembly(void)
00043 {
00044
00045 QVBoxLayout *layout=new QVBoxLayout();
00046 layout->setMargin(8);
00047 layout->setSpacing(10);
00048
00049
00050 layout->addWidget(infofield);
00051 layout->addWidget(buttonbox,0,Qt::AlignRight);
00052
00053 layout->setSizeConstraint(QLayout::SetFixedSize);
00054
00055 setLayout(layout);
00056
00057
00058
00059
00060 infofield->set_focus_to_start();
00061
00062
00063
00064
00065
00066 }
00067
00068
00069 void editrecord::ok_click(void)
00070 {
00071 QString message="";
00072
00073
00074 if(infofield->get_field("name").length()==0)
00075 message=message+tr("Please enter title of record. ");
00076
00077
00078 if(message.length()>0)
00079 {
00080 QMessageBox::warning(this,tr("Record fields cannot edit"),message,
00081 QMessageBox::Close);
00082 return;
00083 }
00084 else
00085 {
00086 emit(accept());
00087 }
00088 }
00089
00090
00091 QString editrecord::get_field(QString name)
00092 {
00093 if(infofield->check_field_name(name)==true)
00094 return infofield->get_field(name);
00095 else
00096 critical_error("Can not get field "+name+" in editrecord method get_field");
00097
00098 return QString();
00099 }
00100
00101
00102 void editrecord::set_field(QString name, QString value)
00103 {
00104 if(infofield->check_field_name(name)==true)
00105 infofield->set_field(name,value);
00106 else
00107 critical_error("Can not set field "+name+" in editrecord method set_field");
00108 }
00109