📄 logindlg.cpp
字号:
/* Demo program for iksemel external sockets.** Copyright (C) 2004-2005 Darrell Karbott (djk2005@users.sf.net)** This code is free software; you can redistribute it and/or** modify it under the terms of the GNU Public Licence (GPL) version 2** See http://www.gnu.org/ for further details of the GPL.*/#include "LoginDlg.h"#include <qlabel.h>#include <qlayout.h>#include <qpushbutton.h>// Stringsconst char* LABEL_USERNAME = "User Name:";const char* LABEL_SERVERNAME = "Server Name:";const char* LABEL_PASSWORD = "Password:" ;const char* LABEL_LOGININFO = "Jabber Login Info";const char* DEFAULT_USERNAME = "<SET_USER>";const char* DEFAULT_SERVERNAME = "jabber.org";const char* DEFAULT_PASSWORD = "";LoginDialog::LoginDialog(QWidget* parent) : QDialog(parent, 0, true){ setCaption(LABEL_LOGININFO); // Stack pairs of widgets vertically. QVBoxLayout* layout = new QVBoxLayout(this, 5); // first QHBoxLayout* firstRow = new QHBoxLayout(layout, 5); QLabel* lblUserName = new QLabel(LABEL_USERNAME, this); firstRow->addWidget(lblUserName); firstRow->addStretch(); txtUserName_ = new QLineEdit(this); firstRow->addWidget(txtUserName_); // second QHBoxLayout* secondRow = new QHBoxLayout(layout, 5); QLabel* lblServerName = new QLabel(LABEL_SERVERNAME, this); secondRow->addWidget(lblServerName); secondRow->addStretch(); txtServerName_ = new QLineEdit(this); secondRow->addWidget(txtServerName_); // third QHBoxLayout* thirdRow = new QHBoxLayout(layout, 5); QLabel* lblPassword = new QLabel(LABEL_PASSWORD, this); thirdRow->addWidget(lblPassword); thirdRow->addStretch(); txtPassword_ = new QLineEdit(this); txtPassword_->setEchoMode(QLineEdit::Password); thirdRow->addWidget(txtPassword_); // Put a vertical space between third and fourth rows if possible. layout->addSpacing(10); layout->addStretch(); // fourth QHBoxLayout* fourthRow = new QHBoxLayout(layout, 5); fourthRow->addStretch(); QPushButton* ok = new QPushButton("&OK", this); connect( ok, SIGNAL(clicked()), this, SLOT(onOk())); ok->setDefault(true); fourthRow->addWidget(ok); QPushButton* cancel = new QPushButton("&Cancel", this); connect( cancel, SIGNAL(clicked()), this, SLOT(onCancel())); fourthRow->addWidget(cancel); txtUserName_->setText(DEFAULT_USERNAME); txtServerName_->setText(DEFAULT_SERVERNAME); txtPassword_->setText(DEFAULT_PASSWORD);}QString LoginDialog::userName() const{ return txtUserName_->text().stripWhiteSpace();}QString LoginDialog::serverName() const{ return txtServerName_->text().stripWhiteSpace();}QString LoginDialog::password() const{ return txtPassword_->text().stripWhiteSpace();}void LoginDialog::onOk(){ QString user = txtUserName_->text(); user = user.stripWhiteSpace(); QString server = txtServerName_->text(); server = server.stripWhiteSpace(); QString password = txtPassword_->text(); password = password.stripWhiteSpace(); if (user.length() < 1 || server.length() < 1 || password.length() < 1) { return; } accept();}void LoginDialog::onCancel(){ reject();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -