libyui-qt  2.49.2
QY2RelNotesDialog.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: QY2RelNotesDialog.cc
20 
21  Author: Jiri Srain <jsrain@suse.de>
22 
23  Textdomain "qt"
24 
25 /-*/
26 
27 #include "QY2RelNotesDialog.h"
28 #include <QDebug>
29 #include <QTextObject>
30 #include "YQi18n.h"
31 #include "YQUI.h"
32 #include "QY2Styler.h"
33 #define YUILogComponent "qt-ui"
34 #include <yui/YUILog.h>
35 
36 
37 #ifdef TEXTDOMAIN
38 # undef TEXTDOMAIN
39 #endif
40 
41 #define TEXTDOMAIN "qt"
42 
43 
44 QY2RelNotesDialog::QY2RelNotesDialog( QWidget *parent )
45  : QDialog( parent )
46 {
47  if (this->objectName().isEmpty())
48  this->setObjectName(QStringLiteral("QRelNotesDialog"));
49  this->resize(581, 388); // same size as help pop-up, proven over time
50  vboxLayout = new QVBoxLayout(this);
51  vboxLayout->setObjectName(QStringLiteral("vboxLayout"));
52 
53  tabBar = new QTabBar( this );
54  Q_CHECK_PTR( tabBar );
55 
56  tabBar->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) ); // hor/vert
57  setFocusProxy( tabBar );
58  setFocusPolicy( Qt::TabFocus );
59 
60  QObject::connect( tabBar, SIGNAL(currentChanged(int)), this, SLOT(tabChanged( int )));
61 
62  vboxLayout->addWidget(tabBar);
63 
64  textBrowser = new QTextBrowser(this);
65  textBrowser->setObjectName(QStringLiteral("textBrowser"));
66 
67  vboxLayout->addWidget(textBrowser);
68 
69  hboxLayout = new QHBoxLayout();
70  closeButton = new QPushButton(this);
71  closeButton->setObjectName(QStringLiteral("closeButton"));
72  hboxLayout->addStretch();
73  hboxLayout->addWidget(closeButton);
74  hboxLayout->addStretch();
75 
76  vboxLayout->addLayout(hboxLayout);
77 
78  QObject::connect(closeButton, SIGNAL(clicked()), this, SLOT(accept()));
79 
80  YQUI::setTextdomain( TEXTDOMAIN );
81 
82  // Window title for help wizard window
83  setWindowTitle( _( "Release Notes" ) );
84 
85  // Close button for wizard help window
86  closeButton->setText( _( "&Close" ) );
87 
88  QY2Styler::styler()->registerWidget( this );
89  // the stylesheet for the displayed text is set separately
90  textBrowser->document()->setDefaultStyleSheet( QY2Styler::styler()->textStyle() );
91 }
92 
93 void QY2RelNotesDialog::setRelNotes( const std::map<std::string,std::string>& relnotes )
94 {
95  while (tabBar->count() > 0)
96  {
97  tabBar->removeTab( 0 );
98  }
99 
100  _relnotes = relnotes;
101  _tab_keys = std::vector<std::string>();
102  for(std::map<std::string,std::string>::const_iterator it = relnotes.begin(); it != relnotes.end(); ++it) {
103  _tab_keys.push_back(it->first);
104  tabBar->addTab( it->first.c_str() );
105  }
106  if (_relnotes.size() > 1)
107  {
108  tabBar->show();
109  }
110  else
111  {
112  tabBar->hide();
113  }
114  textBrowser->setText( relnotes.begin()->second.c_str() );
115 }
116 
117 QY2RelNotesDialog::~QY2RelNotesDialog()
118 {
119  QY2Styler::styler()->unregisterWidget( this );
120 }
121 
122 void QY2RelNotesDialog::tabChanged( int index )
123 {
124  if (index < 0 || _tab_keys.empty() || _relnotes.empty())
125  {
126  return;
127  }
128  textBrowser->setText( _relnotes[_tab_keys[index]].c_str() );
129 }
130 
131 void QY2RelNotesDialog::retranslate()
132 {
133  setWindowTitle( _( "Release Notes" ) );
134  closeButton->setText( _( "&Close" ) );
135 }
136 
137 
138 
139 #include "QY2RelNotesDialog.moc"
void registerWidget(QWidget *widget)
Registers a widget and applies the style sheet.
Definition: QY2Styler.cc:268
void unregisterWidget(QWidget *widget)
Unregisters a widget.
Definition: QY2Styler.cc:277
static void setTextdomain(const char *domain)
Initialize and set a textdomain for gettext()
Definition: YQUI.cc:488