URLFormWidget::URLFormWidget(QWidget *parent) : AbstractFormWidget(parent), m_markEmpty(false) { m_fieldNameLabel = new QLabel("Invalid Name", this); m_mainLayout = new QVBoxLayout(this); m_lineEdit = new QLineEdit(this); m_openURLAction = m_lineEdit->addAction(QIcon(":/images/icons/browser.png"), QLineEdit::TrailingPosition); m_openURLAction->setToolTip(tr("Open web link")); //static styling m_fieldNameLabel->setStyleSheet("QLabel {color: gray;}"); //on mac disable focus rect around rounded borders m_lineEdit->setAttribute(Qt::WA_MacShowFocusRect, 0); m_mainLayout->addWidget(m_fieldNameLabel); m_mainLayout->addWidget(m_lineEdit); m_mainLayout->addStretch(); this->heightUnits = 1; this->widthUnits = 1; //connections connect(m_lineEdit, SIGNAL(editingFinished()), this, SLOT(validateData())); connect(m_openURLAction, SIGNAL(triggered()), this, SLOT(openURLActionTriggered())); updateFocusPolicy(); }
BE::Contacts::Contacts(AbookAddressbook *abook): m_abook(abook), m_dirty(false) { m_currentContact = 0; QImage img(QDir::homePath() + QLatin1String("/.abook/incognito.png")); if (!img.isNull()) m_incognitoPic = QPixmap::fromImage(img.scaled(160,160,Qt::KeepAspectRatio,Qt::SmoothTransformation)); m_ui = new Ui::Contacts; m_ui->setupUi(this); #if QT_VERSION >= 0x040700 m_ui->filter->setPlaceholderText(tr("Filter")); #endif m_ui2 = new Ui::OneContact; m_ui2->setupUi(m_ui->oneContact); fields << Field(AbookAddressbook::Name, m_ui2->name, QLatin1String("name")) << Field(AbookAddressbook::Mail, m_ui2->mail, QLatin1String("email")) << Field(AbookAddressbook::Address, m_ui2->address, QLatin1String("address")) << Field(AbookAddressbook::City, m_ui2->city, QLatin1String("city")) << Field(AbookAddressbook::State, m_ui2->state, QLatin1String("state")) << Field(AbookAddressbook::ZIP, m_ui2->zip, QLatin1String("zip")) << Field(AbookAddressbook::Country, m_ui2->country, QLatin1String("country")) << Field(AbookAddressbook::Phone, m_ui2->phone, QLatin1String("phone")) << Field(AbookAddressbook::Workphone, m_ui2->workphone, QLatin1String("workphone")) << Field(AbookAddressbook::Fax, m_ui2->fax, QLatin1String("fax")) << Field(AbookAddressbook::Mobile, m_ui2->mobile, QLatin1String("mobile")) << Field(AbookAddressbook::Nick, m_ui2->nick, QLatin1String("nick")) << Field(AbookAddressbook::URL, m_ui2->url, QLatin1String("url")) << Field(AbookAddressbook::Notes, m_ui2->notes, QLatin1String("notes")) << Field(AbookAddressbook::Anniversary, m_ui2->anniversary, QLatin1String("anniversary")) << Field(AbookAddressbook::Photo, m_ui2->photo, QLatin1String("photo")); m_sortFilterProxy = new QSortFilterProxyModel(this); m_sortFilterProxy->setFilterCaseSensitivity(Qt::CaseInsensitive); m_sortFilterProxy->setFilterKeyColumn(-1); m_sortFilterProxy->setSourceModel(m_abook->model()); connect (m_ui->filter, SIGNAL(textChanged(QString)), m_sortFilterProxy, SLOT(setFilterWildcard(QString))); m_ui->filter->installEventFilter(this); QFont fnt = m_ui2->name->font(); fnt.setPointSize(fnt.pointSize()*2); m_ui2->name->setFont(fnt); for (QList<Field>::const_iterator it = fields.constBegin(), end = fields.constEnd(); it != end; ++it) { it->label->installEventFilter(this); } m_ui->contacts->setModel(m_sortFilterProxy); m_ui->contacts->setSelectionMode(QAbstractItemView::SingleSelection); connect (m_ui->contacts->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(setContact(QModelIndex))); QModelIndex idx = m_sortFilterProxy->index(0,0); if (idx.isValid()) m_ui->contacts->setCurrentIndex(idx); m_ui->contacts->installEventFilter(this); connect (m_ui->add, SIGNAL(clicked()), SLOT(addContact())); connect (m_ui->remove, SIGNAL(clicked()), SLOT(removeCurrentContact())); connect (qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), SLOT(updateFocusPolicy(QWidget*, QWidget*))); // cheat to correct the focuspolicies ;-) updateFocusPolicy(m_ui2->name, m_ui->filter); Q_FOREACH(const Field &field, fields) { if (QTextDocument *doc = field.label->findChild<QTextDocument*>()) connect(doc, SIGNAL(contentsChanged()), SLOT(updateLabel())); } }