VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/UILineTextEdit.cpp@ 76553

Last change on this file since 76553 was 76553, checked in by vboxsync, 5 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
1/* $Id: UILineTextEdit.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UILineTextEdit class definitions.
4 */
5
6/*
7 * Copyright (C) 2009-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifdef VBOX_WITH_PRECOMPILED_HEADERS
19# include <precomp.h>
20#else /* !VBOX_WITH_PRECOMPILED_HEADERS */
21
22/* Qt includes: */
23# include <QDialogButtonBox>
24# include <QFile>
25# include <QLineEdit>
26# include <QPushButton>
27# include <QTextEdit>
28# include <QTextStream>
29# include <QVBoxLayout>
30
31/* GUI includes: */
32# include "QIFileDialog.h"
33# include "VBoxGlobal.h"
34# include "UILineTextEdit.h"
35
36#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
37
38
39////////////////////////////////////////////////////////////////////////////////
40// UITextEditor
41
42UITextEditor::UITextEditor(QWidget *pParent /* = NULL */)
43 : QIWithRetranslateUI<QIDialog>(pParent)
44{
45 QVBoxLayout *pMainLayout = new QVBoxLayout(this);
46 pMainLayout->setMargin(12);
47
48 /* We need a text editor */
49 m_pTextEdit = new QTextEdit(this);
50 pMainLayout->addWidget(m_pTextEdit);
51 /* and some buttons to interact with */
52 m_pButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
53 m_pOpenButton = new QPushButton(this);
54 m_pButtonBox->addButton(m_pOpenButton, QDialogButtonBox::ActionRole);
55 pMainLayout->addWidget(m_pButtonBox);
56 /* Connect the buttons so that they are useful */
57 connect(m_pButtonBox, SIGNAL(accepted()),
58 this, SLOT(accept()));
59 connect(m_pButtonBox, SIGNAL(rejected()),
60 this, SLOT(reject()));
61 connect(m_pOpenButton, SIGNAL(clicked()),
62 this, SLOT(open()));
63
64 /* Applying language settings */
65 retranslateUi();
66}
67
68void UITextEditor::setText(const QString& strText)
69{
70 m_pTextEdit->setText(strText);
71}
72
73QString UITextEditor::text() const
74{
75 return m_pTextEdit->toPlainText();
76}
77
78void UITextEditor::retranslateUi()
79{
80 setWindowTitle(tr("Edit text"));
81 m_pOpenButton->setText(tr("&Replace..."));
82 m_pOpenButton->setToolTip(tr("Replaces the current text with the content of a file."));
83}
84
85void UITextEditor::open()
86{
87 QString fileName = QIFileDialog::getOpenFileName(vboxGlobal().documentsPath(), tr("Text (*.txt);;All (*.*)"), this, tr("Select a file to open..."));
88 if (!fileName.isEmpty())
89 {
90 QFile file(fileName);
91 if (file.open(QFile::ReadOnly))
92 {
93 QTextStream in(&file);
94 m_pTextEdit->setPlainText(in.readAll());
95 }
96 }
97
98}
99
100////////////////////////////////////////////////////////////////////////////////
101// UILineTextEdit
102
103UILineTextEdit::UILineTextEdit(QWidget *pParent /* = NULL */)
104 : QIWithRetranslateUI<QPushButton>(pParent)
105{
106 connect(this, SIGNAL(clicked()),
107 this, SLOT(edit()));
108
109 /* Don't interpret the Enter Key. */
110 setAutoDefault(false);
111 setDefault(false);
112
113 setFocusPolicy(Qt::StrongFocus);
114 retranslateUi();
115}
116
117void UILineTextEdit::retranslateUi()
118{
119 QPushButton::setText(tr("&Edit"));
120}
121
122void UILineTextEdit::edit()
123{
124 UITextEditor te(this);
125 te.setText(m_strText);
126 if (te.exec() == QDialog::Accepted)
127 {
128 m_strText = te.text();
129 /* Notify listener(s) about we finished: */
130 emit sigFinished(this);
131 }
132}
133
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use