GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
TextControl.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2011-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include <QLabel>
31
32#include "Container.h"
33#include "TextControl.h"
34#include "QtHandlesUtils.h"
35
36#include "octave-qobject.h"
37
38namespace octave
39{
40
41 TextControl *
43 octave::interpreter& interp, const graphics_object& go)
44 {
45 Object *parent = parentObject (interp, go);
46
47 if (parent)
48 {
49 Container *container = parent->innerContainer ();
50
51 if (container)
52 return new TextControl (oct_qobj, interp, go, new QLabel (container));
53 }
54
55 return nullptr;
56 }
57
59 octave::interpreter& interp,
60 const graphics_object& go, QLabel *label)
61 : BaseControl (oct_qobj, interp, go, label)
62 {
63 uicontrol::properties& up = properties<uicontrol> ();
64
65 label->setAutoFillBackground (true);
66 label->setTextFormat (Qt::PlainText);
67 label->setWordWrap (false);
68 label->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (),
69 up.get_verticalalignment ()));
70 label->setText (Utils::fromStringVector (up.get_string_vector ()).join ("\n"));
71 }
72
74 { }
75
76 void
78 {
79 uicontrol::properties& up = properties<uicontrol> ();
80 QLabel *label = qWidget<QLabel> ();
81
82 switch (pId)
83 {
84 case uicontrol::properties::ID_STRING:
85 label->setText (Utils::fromStringVector (up.get_string_vector ()).join ("\n"));
86 break;
87
88 case uicontrol::properties::ID_HORIZONTALALIGNMENT:
89 case uicontrol::properties::ID_VERTICALALIGNMENT:
90 label->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (),
91 up.get_verticalalignment ()));
92 break;
93
94 default:
96 break;
97 }
98 }
99
100}
void update(int pId)
Definition: BaseControl.cc:165
virtual Container * innerContainer(void)=0
static Object * parentObject(octave::interpreter &interp, const graphics_object &go)
Definition: Object.cc:201
TextControl(octave::base_qobject &oct_qobj, octave::interpreter &interp, const graphics_object &go, QLabel *label)
Definition: TextControl.cc:58
static TextControl * create(octave::base_qobject &oct_qobj, octave::interpreter &interp, const graphics_object &go)
Definition: TextControl.cc:42
void update(int pId)
Definition: TextControl.cc:77
Base class for Octave interfaces that use Qt.
QStringList fromStringVector(const string_vector &v)
Qt::Alignment fromHVAlign(const std::string &halign, const std::string &valign)
T::properties & properties(graphics_object obj)