addnewrecord.cpp

Go to the documentation of this file.
00001 #include <QWidget>
00002 #include <QTextEdit>
00003 #include <QtDebug>
00004 #include <QSizePolicy>
00005 #include <QIcon>
00006 #include <QMessageBox>
00007 #include <QTextDocumentFragment>
00008 
00009 #include "addnewrecord.h"
00010 #include "main.h"
00011 
00012 
00013 addnewrecord::addnewrecord( QWidget * parent, Qt::WFlags f) : QDialog(parent, f)
00014 {
00015  setup_ui();
00016  setup_signals();
00017  assembly();
00018 }
00019 
00020 addnewrecord::~addnewrecord()
00021 {
00022 
00023 }
00024 
00025 
00026 void addnewrecord::setup_ui(void)
00027 {
00028  this->setWindowTitle(tr("Enter new record"));
00029   
00030  // Ввод инфополей записи
00031  infofield=new infofieldenter();
00032 
00033  // Редактор текста записи
00034  recordtext_editor=new editor(ENABLE_ASSEMBLY);
00035 
00036  // Кнопки OK и Cancel
00037  buttonbox=new QDialogButtonBox();
00038  buttonbox->setOrientation(Qt::Horizontal);
00039  buttonbox->setStandardButtons(QDialogButtonBox::Ok|QDialogButtonBox::NoButton|QDialogButtonBox::Cancel);
00040 }
00041 
00042 void addnewrecord::setup_signals(void)
00043 {
00044  connect(buttonbox, SIGNAL(accepted()), this, SLOT(ok_click(void)));
00045  connect(buttonbox, SIGNAL(rejected()), this, SLOT(reject()));
00046 }
00047 
00048 void addnewrecord::assembly(void)
00049 {
00050  // Размещалка элементов
00051  QVBoxLayout *layout=new QVBoxLayout();
00052  layout->setMargin(8);
00053  layout->setSpacing(10);
00054 
00055  // Добавление элементов в размещалку
00056  layout->addWidget(infofield);
00057  layout->addWidget(recordtext_editor);
00058  layout->addWidget(buttonbox,0,Qt::AlignRight);
00059 
00060  setLayout(layout);
00061 
00062  // Фокус устанавливается на поле ввода названия записи
00063  infofield->set_focus_to_start();
00064 
00065  // QWidget *wdgt=new QWidget;
00066  // wdgt->setLayout(vbl);
00067  // setCentralWidget(wdgt);
00068 }
00069 
00070 
00071 void addnewrecord::ok_click(void)
00072 {
00073  QString message="";
00074 
00075  // Проверка наличия названия записи
00076  if(infofield->get_field("name").length()==0)
00077   message=message+tr("Please enter title of record. ");
00078 
00079  // Проверка наличия текста записи
00080  QTextDocumentFragment i;
00081  QString j;
00082  i=QTextDocumentFragment::fromHtml(get_field("text"));
00083  j=i.toPlainText();
00084  qDebug() << "recordtext " << j;
00085  if(j.length()==0)
00086   message=message+tr("Please enter text of record. ");
00087 
00088  // Если что-то не заполнено, выдается предупреждение
00089  if(message.length()>0)
00090   {
00091    QMessageBox::warning(this,tr("New record cannot added"),message,
00092                         QMessageBox::Close);
00093    return;
00094   }
00095  else
00096   {
00097    emit(accept());
00098   }
00099 }
00100 
00101 
00102 QString addnewrecord::get_field(QString name)
00103 {
00104  if(name=="name" ||
00105     name=="author" ||
00106     name=="url" ||
00107     name=="tags")
00108   return infofield->get_field(name);
00109 
00110  if(name=="text")
00111   return recordtext_editor->get_textarea();
00112 
00113  // Если запрашиваемого поля нет, возвращается пустая строка
00114  return QString();
00115 }

Generated on Mon Feb 2 00:25:33 2009 for mytetra by  doxygen 1.5.1