14 changed files with 265 additions and 5 deletions
			
			
		@ -0,0 +1,25 @@ | 
				
			|||||
 | 
					#include "tabitemview.h" | 
				
			||||
 | 
					#include "ui_tabitemview.h" | 
				
			||||
 | 
					#include <QtMvvmCore/Binding> | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					TabItemView::TabItemView(QtMvvm::ViewModel *viewModel, QWidget *parent) : | 
				
			||||
 | 
						QWidget(parent), | 
				
			||||
 | 
						_viewModel(static_cast<TabItemViewModel*>(viewModel)), | 
				
			||||
 | 
						ui(new Ui::TabItemView) | 
				
			||||
 | 
					{ | 
				
			||||
 | 
						ui->setupUi(this); | 
				
			||||
 | 
					
 | 
				
			||||
 | 
						QtMvvm::bind(_viewModel, "title", | 
				
			||||
 | 
									 ui->checkBox, "text", | 
				
			||||
 | 
									 QtMvvm::Binding::OneWayToView); | 
				
			||||
 | 
					} | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					TabItemView::~TabItemView() | 
				
			||||
 | 
					{ | 
				
			||||
 | 
						delete ui; | 
				
			||||
 | 
					} | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					TabItemViewModel *TabItemView::viewModel() const | 
				
			||||
 | 
					{ | 
				
			||||
 | 
						return _viewModel; | 
				
			||||
 | 
					} | 
				
			||||
@ -0,0 +1,26 @@ | 
				
			|||||
 | 
					#ifndef TABITEMVIEW_H | 
				
			||||
 | 
					#define TABITEMVIEW_H | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					#include <QWidget> | 
				
			||||
 | 
					#include <tabviewmodel.h> | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					namespace Ui { | 
				
			||||
 | 
					class TabItemView; | 
				
			||||
 | 
					} | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					class TabItemView : public QWidget | 
				
			||||
 | 
					{ | 
				
			||||
 | 
						Q_OBJECT | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					public: | 
				
			||||
 | 
						Q_INVOKABLE explicit TabItemView(QtMvvm::ViewModel *viewModel, QWidget *parent = nullptr); | 
				
			||||
 | 
						~TabItemView(); | 
				
			||||
 | 
					
 | 
				
			||||
 | 
						TabItemViewModel *viewModel() const; | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					private: | 
				
			||||
 | 
						TabItemViewModel *_viewModel; | 
				
			||||
 | 
						Ui::TabItemView *ui; | 
				
			||||
 | 
					}; | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					#endif // TABITEMVIEW_H
 | 
				
			||||
@ -0,0 +1,84 @@ | 
				
			|||||
 | 
					<?xml version="1.0" encoding="UTF-8"?> | 
				
			||||
 | 
					<ui version="4.0"> | 
				
			||||
 | 
					 <class>TabItemView</class> | 
				
			||||
 | 
					 <widget class="QWidget" name="TabItemView"> | 
				
			||||
 | 
					  <property name="geometry"> | 
				
			||||
 | 
					   <rect> | 
				
			||||
 | 
					    <x>0</x> | 
				
			||||
 | 
					    <y>0</y> | 
				
			||||
 | 
					    <width>400</width> | 
				
			||||
 | 
					    <height>300</height> | 
				
			||||
 | 
					   </rect> | 
				
			||||
 | 
					  </property> | 
				
			||||
 | 
					  <property name="windowTitle"> | 
				
			||||
 | 
					   <string>Form</string> | 
				
			||||
 | 
					  </property> | 
				
			||||
 | 
					  <layout class="QVBoxLayout" name="verticalLayout"> | 
				
			||||
 | 
					   <item> | 
				
			||||
 | 
					    <spacer name="verticalSpacer"> | 
				
			||||
 | 
					     <property name="orientation"> | 
				
			||||
 | 
					      <enum>Qt::Vertical</enum> | 
				
			||||
 | 
					     </property> | 
				
			||||
 | 
					     <property name="sizeHint" stdset="0"> | 
				
			||||
 | 
					      <size> | 
				
			||||
 | 
					       <width>20</width> | 
				
			||||
 | 
					       <height>119</height> | 
				
			||||
 | 
					      </size> | 
				
			||||
 | 
					     </property> | 
				
			||||
 | 
					    </spacer> | 
				
			||||
 | 
					   </item> | 
				
			||||
 | 
					   <item> | 
				
			||||
 | 
					    <layout class="QHBoxLayout" name="horizontalLayout"> | 
				
			||||
 | 
					     <item> | 
				
			||||
 | 
					      <spacer name="horizontalSpacer"> | 
				
			||||
 | 
					       <property name="orientation"> | 
				
			||||
 | 
					        <enum>Qt::Horizontal</enum> | 
				
			||||
 | 
					       </property> | 
				
			||||
 | 
					       <property name="sizeHint" stdset="0"> | 
				
			||||
 | 
					        <size> | 
				
			||||
 | 
					         <width>40</width> | 
				
			||||
 | 
					         <height>20</height> | 
				
			||||
 | 
					        </size> | 
				
			||||
 | 
					       </property> | 
				
			||||
 | 
					      </spacer> | 
				
			||||
 | 
					     </item> | 
				
			||||
 | 
					     <item> | 
				
			||||
 | 
					      <widget class="QCheckBox" name="checkBox"> | 
				
			||||
 | 
					       <property name="text"> | 
				
			||||
 | 
					        <string>CheckBox</string> | 
				
			||||
 | 
					       </property> | 
				
			||||
 | 
					      </widget> | 
				
			||||
 | 
					     </item> | 
				
			||||
 | 
					     <item> | 
				
			||||
 | 
					      <spacer name="horizontalSpacer_2"> | 
				
			||||
 | 
					       <property name="orientation"> | 
				
			||||
 | 
					        <enum>Qt::Horizontal</enum> | 
				
			||||
 | 
					       </property> | 
				
			||||
 | 
					       <property name="sizeHint" stdset="0"> | 
				
			||||
 | 
					        <size> | 
				
			||||
 | 
					         <width>40</width> | 
				
			||||
 | 
					         <height>20</height> | 
				
			||||
 | 
					        </size> | 
				
			||||
 | 
					       </property> | 
				
			||||
 | 
					      </spacer> | 
				
			||||
 | 
					     </item> | 
				
			||||
 | 
					    </layout> | 
				
			||||
 | 
					   </item> | 
				
			||||
 | 
					   <item> | 
				
			||||
 | 
					    <spacer name="verticalSpacer_2"> | 
				
			||||
 | 
					     <property name="orientation"> | 
				
			||||
 | 
					      <enum>Qt::Vertical</enum> | 
				
			||||
 | 
					     </property> | 
				
			||||
 | 
					     <property name="sizeHint" stdset="0"> | 
				
			||||
 | 
					      <size> | 
				
			||||
 | 
					       <width>20</width> | 
				
			||||
 | 
					       <height>119</height> | 
				
			||||
 | 
					      </size> | 
				
			||||
 | 
					     </property> | 
				
			||||
 | 
					    </spacer> | 
				
			||||
 | 
					   </item> | 
				
			||||
 | 
					  </layout> | 
				
			||||
 | 
					 </widget> | 
				
			||||
 | 
					 <resources/> | 
				
			||||
 | 
					 <connections/> | 
				
			||||
 | 
					</ui> | 
				
			||||
@ -0,0 +1,40 @@ | 
				
			|||||
 | 
					#include "tabview.h" | 
				
			||||
 | 
					#include "ui_tabview.h" | 
				
			||||
 | 
					#include "tabitemview.h" | 
				
			||||
 | 
					TabView::TabView(QtMvvm::ViewModel *viewModel, QWidget *parent) : | 
				
			||||
 | 
						QTabWidget(parent), | 
				
			||||
 | 
						IPresentingView(), | 
				
			||||
 | 
						_viewModel(static_cast<TabViewModel*>(viewModel)), | 
				
			||||
 | 
						ui(new Ui::TabView) | 
				
			||||
 | 
					{ | 
				
			||||
 | 
						setWindowFlags(windowFlags() | Qt::Window); | 
				
			||||
 | 
						ui->setupUi(this); | 
				
			||||
 | 
					
 | 
				
			||||
 | 
						tabBar()->addTab(QStringLiteral("+")); | 
				
			||||
 | 
					
 | 
				
			||||
 | 
						connect(tabBar(), &QTabBar::tabBarClicked, | 
				
			||||
 | 
								this, &TabView::trigger); | 
				
			||||
 | 
					} | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					TabView::~TabView() | 
				
			||||
 | 
					{ | 
				
			||||
 | 
						delete ui; | 
				
			||||
 | 
					} | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					bool TabView::tryPresent(QWidget *view) | 
				
			||||
 | 
					{ | 
				
			||||
 | 
						auto itemView = qobject_cast<TabItemView*>(view); | 
				
			||||
 | 
						if(itemView) { | 
				
			||||
 | 
							insertTab(count() - 1, itemView, itemView->viewModel()->title()); | 
				
			||||
 | 
							tabBar()->setCurrentIndex(tabBar()->count() - 2); | 
				
			||||
 | 
							return true; | 
				
			||||
 | 
						} else | 
				
			||||
 | 
							return true; | 
				
			||||
 | 
					} | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					void TabView::trigger(int index) | 
				
			||||
 | 
					{ | 
				
			||||
 | 
						tabBar()->setCurrentIndex(tabBar()->count() - 1); | 
				
			||||
 | 
						if(index == tabBar()->count() - 1) | 
				
			||||
 | 
							_viewModel->addTab(); | 
				
			||||
 | 
					} | 
				
			||||
@ -0,0 +1,31 @@ | 
				
			|||||
 | 
					#ifndef TABVIEW_H | 
				
			||||
 | 
					#define TABVIEW_H | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					#include <QtWidgets/QTabWidget> | 
				
			||||
 | 
					#include <QtMvvmWidgets/IPresentingView> | 
				
			||||
 | 
					#include <tabviewmodel.h> | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					namespace Ui { | 
				
			||||
 | 
					class TabView; | 
				
			||||
 | 
					} | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					class TabView : public QTabWidget, public QtMvvm::IPresentingView | 
				
			||||
 | 
					{ | 
				
			||||
 | 
						Q_OBJECT | 
				
			||||
 | 
						Q_INTERFACES(QtMvvm::IPresentingView) | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					public: | 
				
			||||
 | 
						Q_INVOKABLE explicit TabView(QtMvvm::ViewModel *viewModel, QWidget *parent = nullptr); | 
				
			||||
 | 
						~TabView(); | 
				
			||||
 | 
					
 | 
				
			||||
 | 
						bool tryPresent(QWidget *view) override; | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					private Q_SLOTS: | 
				
			||||
 | 
						void trigger(int index); | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					private: | 
				
			||||
 | 
						TabViewModel *_viewModel; | 
				
			||||
 | 
						Ui::TabView *ui; | 
				
			||||
 | 
					}; | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					#endif // TABVIEW_H
 | 
				
			||||
@ -0,0 +1,16 @@ | 
				
			|||||
 | 
					<?xml version="1.0" encoding="UTF-8"?> | 
				
			||||
 | 
					<ui version="4.0"> | 
				
			||||
 | 
					 <class>TabView</class> | 
				
			||||
 | 
					 <widget class="QTabWidget" name="TabView"> | 
				
			||||
 | 
					  <property name="geometry"> | 
				
			||||
 | 
					   <rect> | 
				
			||||
 | 
					    <x>0</x> | 
				
			||||
 | 
					    <y>0</y> | 
				
			||||
 | 
					    <width>400</width> | 
				
			||||
 | 
					    <height>300</height> | 
				
			||||
 | 
					   </rect> | 
				
			||||
 | 
					  </property> | 
				
			||||
 | 
					 </widget> | 
				
			||||
 | 
					 <resources/> | 
				
			||||
 | 
					 <connections/> | 
				
			||||
 | 
					</ui> | 
				
			||||
					Loading…
					
					
				
		Reference in new issue