00001 #include <QSizePolicy>
00002
00003 #include "infofieldenter.h"
00004 #include "main.h"
00005 #include "appconfig.h"
00006
00007 extern appconfig mytetraconfig;
00008
00009
00010 infofieldenter::infofieldenter(QWidget *parent) : QWidget(parent)
00011 {
00012 setup_ui();
00013 setup_signals();
00014 assembly();
00015 }
00016
00017 infofieldenter::~infofieldenter()
00018 {
00019
00020 }
00021
00022 void infofieldenter::setup_ui(void)
00023 {
00024
00025 recordname_label=new QLabel(this);
00026 recordname_label->setText(tr("Title"));
00027 recordname=new QLineEdit(this);
00028 recordname->setMinimumWidth(500);
00029
00030
00031 recordauthor_label=new QLabel(this);
00032 recordauthor_label->setText(tr("Author(s)"));
00033 recordauthor=new QLineEdit(this);
00034
00035
00036 recordurl_label=new QLabel(this);
00037 recordurl_label->setText(tr("Url"));
00038 recordurl=new QLineEdit(this);
00039
00040
00041 recordtags_label=new QLabel(this);
00042 recordtags_label->setText(tr("Tags"));
00043 recordtags=new QLineEdit(this);
00044
00045
00046
00047 expand_info=new QToolButton(this);
00048 expand_info->setVisible(true);
00049 int w=expand_info->geometry().width();
00050 int h=expand_info->geometry().height();
00051 int x=imin(w,h)/2;
00052 expand_info->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed, QSizePolicy::ToolButton));
00053 expand_info->setMinimumSize(x,x);
00054 expand_info->setMaximumSize(x,x);
00055 expand_info->resize(x,x);
00056 if(mytetraconfig.get_addnewrecord_expand_info()=="0")
00057 expand_info->setIcon(QIcon("./resource/pic/triangl_dn.svg"));
00058 else
00059 expand_info->setIcon(QIcon("./resource/pic/triangl_up.svg"));
00060 }
00061
00062
00063 void infofieldenter::setup_signals(void)
00064 {
00065 connect(expand_info, SIGNAL(pressed()),this, SLOT(expand_info_click(void)));
00066 }
00067
00068
00069
00070 void infofieldenter::assembly(void)
00071 {
00072
00073 infofieldlayout=new QGridLayout();
00074 infofieldlayout->setMargin(8);
00075 infofieldlayout->setSpacing(10);
00076
00077 int y=-1;
00078
00079 infofieldlayout->addWidget(recordname_label,++y,0);
00080 infofieldlayout->addWidget(recordname,y,1);
00081
00082 infofieldlayout->addWidget(expand_info,y,2);
00083
00084 infofieldlayout->addWidget(recordauthor_label,++y,0);
00085 infofieldlayout->addWidget(recordauthor,y,1);
00086
00087 infofieldlayout->addWidget(recordurl_label,++y,0);
00088 infofieldlayout->addWidget(recordurl,y,1);
00089
00090 infofieldlayout->addWidget(recordtags_label,++y,0);
00091 infofieldlayout->addWidget(recordtags,y,1);
00092
00093
00094 expand_info_on_display( mytetraconfig.get_addnewrecord_expand_info() );
00095
00096
00097 setLayout(infofieldlayout);
00098
00099
00100
00101 QLayout *lt;
00102 lt=layout();
00103 lt->setContentsMargins(0,0,0,0);
00104
00105
00106 }
00107
00108
00109 void infofieldenter::expand_info_on_display(QString expand)
00110 {
00111 bool i;
00112
00113 if(expand=="0")
00114 i=false;
00115 else
00116 i=true;
00117
00118 recordauthor_label->setVisible(i);
00119 recordauthor->setVisible(i);
00120
00121 recordurl_label->setVisible(i);
00122 recordurl->setVisible(i);
00123
00124 recordtags_label->setVisible(i);
00125 recordtags->setVisible(i);
00126 }
00127
00128
00129 void infofieldenter::expand_info_click(void)
00130 {
00131
00132 if(mytetraconfig.get_addnewrecord_expand_info()=="0")
00133 {
00134
00135 expand_info_on_display("1");
00136
00137 mytetraconfig.set_addnewrecord_expand_info("1");
00138
00139 expand_info->setIcon(QIcon("./resource/pic/triangl_up.svg"));
00140 }
00141 else
00142 {
00143
00144 expand_info_on_display("0");
00145
00146 mytetraconfig.set_addnewrecord_expand_info("0");
00147
00148 expand_info->setIcon(QIcon("./resource/pic/triangl_dn.svg"));
00149 }
00150 }
00151
00152
00153 void infofieldenter::set_focus_to_start(void)
00154 {
00155 recordname->setFocus(Qt::TabFocusReason);
00156 }
00157
00158 bool infofieldenter::check_field_name(QString name)
00159 {
00160 if(name=="name" ||
00161 name=="author" ||
00162 name=="url" ||
00163 name=="tags")
00164 return true;
00165 else
00166 return false;
00167 }
00168
00169
00170 QString infofieldenter::get_field(QString name)
00171 {
00172 if(check_field_name(name))
00173 {
00174 if(name=="name") return recordname->text();
00175 if(name=="author")return recordauthor->text();
00176 if(name=="url") return recordurl->text();
00177 if(name=="tags") return recordtags->text();
00178 }
00179 else
00180 critical_error("Can not get field "+name+" in infofieldenter method get_field");
00181
00182 return QString();
00183 }
00184
00185
00186 void infofieldenter::set_field(QString name,QString value)
00187 {
00188 if(check_field_name(name))
00189 {
00190 if(name=="name") recordname->setText(value);
00191 if(name=="author")recordauthor->setText(value);
00192 if(name=="url") recordurl->setText(value);
00193 if(name=="tags") recordtags->setText(value);
00194 }
00195 else
00196 critical_error("Can not set field "+name+" in infofieldenter method set_field");
00197 }