File indexing completed on 2024-04-21 14:56:11
0001 /* This file is part of the KDE libraries 0002 Copyright (C) 1997 Mario Weilguni (mweilguni@sime.com) 0003 Copyright (C) 2006 Olivier Goffart 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include <QApplication> 0021 #include "kdialogbuttonbox.h" 0022 #include <QLayout> 0023 #include <QLabel> 0024 #include <QDialog> 0025 #include <QPushButton> 0026 #include <QBoxLayout> 0027 0028 int main(int argc, char **argv) 0029 { 0030 QApplication a(argc, argv); 0031 0032 // example 1 0033 { 0034 QDialog *w = new QDialog; 0035 w->setObjectName("A common dialog"); 0036 w->setModal(true); 0037 w->setWindowTitle("Example 1"); 0038 QVBoxLayout *tl = new QVBoxLayout(w); 0039 tl->setMargin(5); 0040 QLabel *l = new QLabel("A very common dialog\n\n"\ 0041 "OK and Cancel are left aligned, Help\n"\ 0042 "is right aligned. Try resizing\n"\ 0043 "the window!\n" 0044 "Press OK or Cancel when done" 0045 , w); 0046 l->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); 0047 l->setMinimumSize(l->sizeHint()); 0048 tl->addWidget(l, 1); 0049 KDialogButtonBox *bbox = new KDialogButtonBox(w); 0050 QPushButton *b = bbox->addButton(QLatin1String("OK"), QDialogButtonBox::AcceptRole); 0051 b->setDefault(true); 0052 w->connect(b, SIGNAL(clicked()), 0053 w, SLOT(accept())); 0054 bbox->addButton(QLatin1String("Cancel"), QDialogButtonBox::RejectRole, w, SLOT(accept())); 0055 0056 bbox->addButton(QLatin1String("Help"), QDialogButtonBox::HelpRole); 0057 0058 tl->addWidget(bbox, 0); 0059 tl->activate(); 0060 w->exec(); 0061 delete w; 0062 } 0063 0064 // example 2 0065 { 0066 QDialog *w = new QDialog(nullptr); 0067 w->setObjectName("Vertical"); 0068 w->setModal(true); 0069 w->setWindowTitle("Example 2 "); 0070 QHBoxLayout *tl = new QHBoxLayout(w); 0071 tl->setMargin(5); 0072 QLabel *l = new QLabel("Did I mention that it's possible\n" 0073 "to make vertically aligned buttons\n" 0074 "too?" 0075 , w); 0076 l->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); 0077 l->setMinimumSize(l->sizeHint()); 0078 tl->addWidget(l, 1); 0079 KDialogButtonBox *bbox = new KDialogButtonBox(w, Qt::Vertical); 0080 0081 QPushButton *b = bbox->addButton(QLatin1String("OK"), QDialogButtonBox::AcceptRole); 0082 b->setDefault(true); 0083 w->connect(b, SIGNAL(clicked()), 0084 w, SLOT(accept())); 0085 bbox->addButton(QLatin1String("Cancel"), QDialogButtonBox::RejectRole, w, SLOT(accept())); 0086 0087 bbox->addButton(QLatin1String("Help"), QDialogButtonBox::HelpRole); 0088 0089 tl->addWidget(bbox, 0); 0090 tl->activate(); 0091 w->exec(); 0092 delete w; 0093 } 0094 0095 return 0; 0096 }