LibreCAD
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
lc::ui::LineWidthSelect Class Reference

Dropdown select for line widths. Line widths are hardcoded in the constructor. More...

#include <linewidthselect.h>

Inheritance diagram for lc::ui::LineWidthSelect:
Collaboration diagram for lc::ui::LineWidthSelect:

Public Slots

void onLayerChanged (lc::Layer_CSPtr layer)
 Event when a new layer is selected. More...
 

Public Member Functions

 LineWidthSelect (lc::ui::MetaInfoManager_SPtr metaInfoManager, QWidget *parent=0, bool showByLayer=false, bool showByBlock=false)
 Create widget. More...
 
void setMetaInfoManager (lc::ui::MetaInfoManager_SPtr metaInfoManager)
 Set the MetaInfo manager. More...
 
lc::MetaLineWidth_CSPtr lineWidth ()
 Return selected line width. More...
 
void setWidth (lc::MetaLineWidth_CSPtr lineWidth)
 Select a new width. More...
 

Private Slots

void onActivated (const QString &text)
 

Private Member Functions

void createEntries ()
 
void updateMetaInfoManager ()
 

Private Attributes

lc::ui::MetaInfoManager_SPtr _metaInfoManager
 
QSize qIconSize
 
std::map< QString, double > values
 

Detailed Description

Dropdown select for line widths. Line widths are hardcoded in the constructor.

Definition at line 19 of file linewidthselect.h.

Constructor & Destructor Documentation

LineWidthSelect::LineWidthSelect ( lc::ui::MetaInfoManager_SPtr  metaInfoManager,
QWidget *  parent = 0,
bool  showByLayer = false,
bool  showByBlock = false 
)

Create widget.

Parameters
parentPointer to parent widget
showByLayerAdd "ByLayer" option
showByBlockAdd "ByBlock" option

Definition at line 7 of file linewidthselect.cpp.

7  :
8  QComboBox(parent) {
9 
10  qIconSize = QSize(128, 32);
11  setIconSize(qIconSize);
12 
13  setMaximumHeight(32);
14 
15  if(showByLayer) {
16  addItem(BY_LAYER);
17  }
18  if(showByBlock) {
19  addItem(BY_BLOCK);
20  }
21 
22  values["0.00mm"] = 0.00;
23  values["0.05mm"] = 0.05;
24  values["0.09mm"] = 0.09;
25  values["0.13mm (ISO)"] = 0.13;
26  values["0.15mm"] = 0.15;
27  values["0.18mm (ISO)"] = 0.18;
28  values["0.20mm"] = 0.20;
29  values["0.25mm (ISO)"] = 0.25;
30  values["0.30mm"] = 0.30;
31  values["0.35mm (ISO)"] = 0.35;
32  values["0.40mm"] = 0.40;
33  values["0.50mm (ISO)"] = 0.50;
34  values["0.53mm"] = 0.53;
35  values["0.60mm"] = 0.60;
36  values["0.70mm (ISO)"] = 0.70;
37  values["0.80mm"] = 0.80;
38  values["0.90mm"] = 0.90;
39  values["1.00mm (ISO)"] = 1.00;
40  values["1.06mm"] = 1.06;
41  values["1.20mm"] = 1.20;
42  values["1.40mm (ISO)"] = 1.40;
43  values["1.58mm"] = 1.58;
44  values["2.00mm (ISO)"] = 2.00;
45  values["2.11mm"] = 2.11;
46 
47  createEntries();
48 
49  setMetaInfoManager(metaInfoManager);
50 
51  connect(this, SIGNAL(activated(const QString&)), this, SLOT(onActivated(const QString&)));
52 }
#define BY_BLOCK
Definition: colorselect.h:12
void onActivated(const QString &text)
#define BY_LAYER
Definition: colorselect.h:13
std::map< QString, double > values
void setMetaInfoManager(lc::ui::MetaInfoManager_SPtr metaInfoManager)
Set the MetaInfo manager.

Member Function Documentation

void LineWidthSelect::createEntries ( )
private

Definition at line 54 of file linewidthselect.cpp.

54  {
55  for(auto v : values) {
56  QPixmap pixmap(qIconSize);
57 
58  LinePatternPainter painter(&pixmap, v.second);
59  painter.drawLinePattern();
60 
61  addItem(QIcon(pixmap), v.first);
62  }
63 }
Painting line patterns on a QPaintDevice.
std::map< QString, double > values
lc::MetaLineWidth_CSPtr LineWidthSelect::lineWidth ( )

Return selected line width.

Returns
Pointer to MetaLineWidth or nullptr if ByLayer or invalid value is selected

Definition at line 138 of file linewidthselect.cpp.

138  {
139  if(currentText() == BY_LAYER) {
140  return nullptr;
141  }
142 
143  if(currentText() == BY_BLOCK) {
144  return std::make_shared<const lc::MetaLineWidthByBlock>();
145  }
146 
147  try {
148  return std::make_shared<lc::MetaLineWidthByValue>(values.at(currentText()));
149  }
150  catch (std::out_of_range& e) {
151  return nullptr;
152  }
153 }
#define BY_BLOCK
Definition: colorselect.h:12
#define BY_LAYER
Definition: colorselect.h:13
std::map< QString, double > values
void LineWidthSelect::onActivated ( const QString &  text)
privateslot

Definition at line 155 of file linewidthselect.cpp.

155  {
157 }
void LineWidthSelect::onLayerChanged ( lc::Layer_CSPtr  layer)
slot

Event when a new layer is selected.

Parameters
layerNew selected layer This function update the "ByLayer" preview

Definition at line 65 of file linewidthselect.cpp.

65  {
66  auto index = findText(BY_LAYER);
67 
68  if(index != -1) {
69  QPixmap pixmap(qIconSize);
70 
71  LinePatternPainter painter(&pixmap, layer->lineWidth().width());
72  painter.drawLinePattern();
73 
74  setItemIcon(index, QIcon(pixmap));
76  }
77 }
#define BY_LAYER
Definition: colorselect.h:13
Painting line patterns on a QPaintDevice.
void drawLinePattern()
Paint line.
void LineWidthSelect::setMetaInfoManager ( lc::ui::MetaInfoManager_SPtr  metaInfoManager)

Set the MetaInfo manager.

Parameters
newMetaInfoManager or nullptr

Definition at line 107 of file linewidthselect.cpp.

107  {
108  _metaInfoManager = metaInfoManager;
109 
110  if(metaInfoManager != nullptr && metaInfoManager->lineWidth() != nullptr) {
111  setWidth(metaInfoManager->lineWidth());
112  }
113 }
lc::ui::MetaInfoManager_SPtr _metaInfoManager
void setWidth(lc::MetaLineWidth_CSPtr lineWidth)
Select a new width.
void LineWidthSelect::setWidth ( lc::MetaLineWidth_CSPtr  lineWidth)

Select a new width.

Parameters
widthNew LineWidth Does nothing if the width is not present in the values.

Definition at line 79 of file linewidthselect.cpp.

79  {
80  if(lineWidth == nullptr) {
81  setCurrentText(BY_LAYER);
83  return;
84  }
85 
86  auto byValue = std::dynamic_pointer_cast<const lc::MetaLineWidthByValue>(lineWidth);
87  if(byValue != nullptr) {
88  for (auto v : values) {
89  if (v.second == byValue->width()) {
90  setCurrentText(v.first);
92  break;
93  }
94  }
95 
96  return;
97  }
98 
99  auto byBlock = std::dynamic_pointer_cast<const lc::MetaLineWidthByBlock>(lineWidth);
100  if(byBlock != nullptr) {
101  setCurrentText(BY_BLOCK);
103  return;
104  }
105 }
lc::MetaLineWidth_CSPtr lineWidth()
Return selected line width.
#define BY_BLOCK
Definition: colorselect.h:12
#define BY_LAYER
Definition: colorselect.h:13
std::map< QString, double > values
void LineWidthSelect::updateMetaInfoManager ( )
private

Definition at line 115 of file linewidthselect.cpp.

115  {
116  if(!_metaInfoManager) {
117  return;
118  }
119 
120  if(currentText() == BY_LAYER) {
121  _metaInfoManager->setLineWidth(nullptr);
122  return;
123  }
124 
125  if(currentText() == BY_BLOCK) {
126  _metaInfoManager->setLineWidth(std::make_shared<const lc::MetaLineWidthByBlock>());
127  return;
128  }
129 
130  try {
131  _metaInfoManager->setLineWidth(std::make_shared<lc::MetaLineWidthByValue>(values.at(currentText())));
132  }
133  catch (std::out_of_range& e) {
134  _metaInfoManager->setLineWidth(nullptr);
135  }
136 }
lc::ui::MetaInfoManager_SPtr _metaInfoManager
#define BY_BLOCK
Definition: colorselect.h:12
#define BY_LAYER
Definition: colorselect.h:13
std::map< QString, double > values

Member Data Documentation

lc::ui::MetaInfoManager_SPtr lc::ui::LineWidthSelect::_metaInfoManager
private

Definition at line 67 of file linewidthselect.h.

QSize lc::ui::LineWidthSelect::qIconSize
private

Definition at line 69 of file linewidthselect.h.

std::map<QString, double> lc::ui::LineWidthSelect::values
private

Definition at line 71 of file linewidthselect.h.


The documentation for this class was generated from the following files: