GNU Octave  8.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-2023 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 
39 
41 TextControl::create (octave::base_qobject& oct_qobj,
42  octave::interpreter& interp, const graphics_object& go)
43 {
44  Object *parent = parentObject (interp, go);
45 
46  if (parent)
47  {
48  Container *container = parent->innerContainer ();
49 
50  if (container)
51  return new TextControl (oct_qobj, interp, go, new QLabel (container));
52  }
53 
54  return nullptr;
55 }
56 
57 TextControl::TextControl (octave::base_qobject& oct_qobj,
58  octave::interpreter& interp,
59  const graphics_object& go, QLabel *label)
60  : BaseControl (oct_qobj, interp, go, label)
61 {
62  uicontrol::properties& up = properties<uicontrol> ();
63 
64  label->setAutoFillBackground (true);
65  label->setTextFormat (Qt::PlainText);
66  label->setWordWrap (false);
67  label->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (),
68  up.get_verticalalignment ()));
69  label->setText (Utils::fromStringVector (up.get_string_vector ()).join ("\n"));
70 }
71 
73 { }
74 
75 void
77 {
78  uicontrol::properties& up = properties<uicontrol> ();
79  QLabel *label = qWidget<QLabel> ();
80 
81  switch (pId)
82  {
83  case uicontrol::properties::ID_STRING:
84  label->setText (Utils::fromStringVector (up.get_string_vector ()).join ("\n"));
85  break;
86 
87  case uicontrol::properties::ID_HORIZONTALALIGNMENT:
88  case uicontrol::properties::ID_VERTICALALIGNMENT:
89  label->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (),
90  up.get_verticalalignment ()));
91  break;
92 
93  default:
94  BaseControl::update (pId);
95  break;
96  }
97 }
98 
OCTAVE_END_NAMESPACE(octave)
void update(int pId)
Definition: BaseControl.cc:164
Definition: Object.h:47
static Object * parentObject(octave::interpreter &interp, const graphics_object &go)
Definition: Object.cc:200
virtual Container * innerContainer(void)=0
~TextControl(void)
Definition: TextControl.cc:72
TextControl(octave::base_qobject &oct_qobj, octave::interpreter &interp, const graphics_object &go, QLabel *label)
Definition: TextControl.cc:57
void update(int pId)
Definition: TextControl.cc:76
static TextControl * create(octave::base_qobject &oct_qobj, octave::interpreter &interp, const graphics_object &go)
Definition: TextControl.cc:41
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
Qt::Alignment fromHVAlign(const std::string &halign, const std::string &valign)
QStringList fromStringVector(const string_vector &v)
T::properties & properties(graphics_object obj)