27
27
#include "qsecurelineedit.h"
29
#include <QVBoxLayout>
30
#include <QHBoxLayout>
29
#include <QProgressBar>
30
#include <QApplication>
31
33
#include <QPushButton>
34
#include <QDialogButtonBox>
32
35
#include <QKeyEvent>
34
#include <QMessageBox>
44
void SetForegroundWindowEx( HWND hWnd )
46
//Attach foreground window thread to our thread
47
const DWORD ForeGroundID = GetWindowThreadProcessId(::GetForegroundWindow(),NULL);
48
const DWORD CurrentID = GetCurrentThreadId();
50
AttachThreadInput ( ForeGroundID, CurrentID, TRUE );
52
HWND hLastActivePopupWnd = GetLastActivePopup( hWnd );
53
SetForegroundWindow( hLastActivePopupWnd );
55
//Detach the attached thread
56
AttachThreadInput ( ForeGroundID, CurrentID, FALSE );
57
}// End SetForegroundWindowEx
60
void raiseWindow( QWidget* w )
63
SetForegroundWindowEx( w->winId() );
69
QPixmap icon( QStyle::StandardPixmap which )
71
QPixmap pm = qApp->windowIcon().pixmap( 48, 48 );
73
if ( which != QStyle::SP_CustomBase ) {
74
const QIcon ic = qApp->style()->standardIcon( which );
75
QPainter painter( &pm );
76
const int emblemSize = 22;
77
painter.drawPixmap( pm.width()-emblemSize, 0,
78
ic.pixmap( emblemSize, emblemSize ) );
36
84
PinEntryDialog::PinEntryDialog( QWidget* parent, const char* name, bool modal,
37
85
bool enable_quality_bar )
38
86
: QDialog( parent ), _grabbed( false )
88
setWindowFlags( windowFlags() & ~Qt::WindowContextHelpButtonHint );
41
91
setWindowModality( Qt::ApplicationModal );
44
QBoxLayout* top = new QVBoxLayout( this );
46
QBoxLayout* upperLayout = new QHBoxLayout();
47
top->addLayout( upperLayout );
49
94
_icon = new QLabel( this );
50
_icon->setPixmap( QMessageBox::standardIcon( QMessageBox::Information ) );
51
upperLayout->addWidget( _icon );
53
QBoxLayout* labelLayout = new QVBoxLayout();
54
upperLayout->addLayout( labelLayout );
95
_icon->setPixmap( icon() );
56
97
_error = new QLabel( this );
57
98
_error->setWordWrap(true);
58
labelLayout->addWidget( _error );
100
pal.setColor( QPalette::WindowText, Qt::red );
101
_error->setPalette( pal );
60
104
_desc = new QLabel( this );
61
105
_desc->setWordWrap(true);
62
labelLayout->addWidget( _desc );
64
QGridLayout* grid = new QGridLayout;
65
top->addLayout( grid );
67
108
_prompt = new QLabel( this );
68
grid->addWidget( _prompt, 0, 0 );
69
111
_edit = new QSecureLineEdit( this );
70
112
_edit->setMaxLength( 256 );
71
grid->addWidget( _edit, 0, 1 );
114
_prompt->setBuddy( _edit );
73
116
if (enable_quality_bar)
75
118
_quality_bar_label = new QLabel( this );
76
119
_quality_bar_label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
77
grid->addWidget ( _quality_bar_label, 1, 0 );
78
120
_quality_bar = new QProgressBar( this );
79
121
_quality_bar->setAlignment( Qt::AlignCenter );
80
grid->addWidget( _quality_bar, 1, 1 );
81
122
_have_quality_bar = true;
84
125
_have_quality_bar = false;
86
QBoxLayout* l = new QHBoxLayout();
89
_ok = new QPushButton( tr("OK"), this );
90
_cancel = new QPushButton( tr("Cancel"), this );
94
l->addWidget( _cancel );
127
QDialogButtonBox* const buttons = new QDialogButtonBox( this );
128
buttons->setStandardButtons( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
129
_ok = buttons->button( QDialogButtonBox::Ok );
130
_cancel = buttons->button( QDialogButtonBox::Cancel );
96
132
_ok->setDefault(true);
98
connect( _ok, SIGNAL( clicked() ),
99
this, SIGNAL( accepted() ) );
100
connect( _cancel, SIGNAL( clicked() ),
101
this, SIGNAL( rejected() ) );
134
if ( style()->styleHint( QStyle::SH_DialogButtonBox_ButtonsHaveIcons ) )
136
_ok->setIcon( style()->standardIcon( QStyle::SP_DialogOkButton ) );
137
_cancel->setIcon( style()->standardIcon( QStyle::SP_DialogCancelButton ) );
140
connect( buttons, SIGNAL(accepted()), this, SLOT(accept()) );
141
connect( buttons, SIGNAL(rejected()), this, SLOT(reject()) );
102
142
connect( _edit, SIGNAL( textChanged(secqstring) ),
103
143
this, SLOT( updateQuality(secqstring) ) );
104
connect (this, SIGNAL (accepted ()),
105
this, SLOT (accept ()));
106
connect (this, SIGNAL (rejected ()),
107
this, SLOT (reject ()));
109
145
_edit->setFocus();
147
QGridLayout* const grid = new QGridLayout( this );
148
grid->addWidget( _icon, 0, 0, 5, 1, Qt::AlignTop|Qt::AlignLeft );
149
grid->addWidget( _error, 1, 1, 1, 2 );
150
grid->addWidget( _desc, 2, 1, 1, 2 );
151
//grid->addItem( new QSpacerItem( 0, _edit->height() / 10, QSizePolicy::Minimum, QSizePolicy::Fixed ), 1, 1 );
152
grid->addWidget( _prompt, 3, 1 );
153
grid->addWidget( _edit, 3, 2 );
154
if( enable_quality_bar )
156
grid->addWidget( _quality_bar_label, 4, 1 );
157
grid->addWidget( _quality_bar, 4, 2 );
159
grid->addWidget( buttons, 5, 0, 1, 3 );
161
grid->setSizeConstraint( QLayout::SetFixedSize );
112
164
void PinEntryDialog::hideEvent( QHideEvent* ev )