mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Resolution-independent trash icon
Also, generate the corresponding pixmap only once, and distribute it to all models that need it. Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
		
							parent
							
								
									60702f104c
								
							
						
					
					
						commit
						dfec501e7a
					
				
					 4 changed files with 44 additions and 5 deletions
				
			
		|  | @ -615,7 +615,13 @@ QVariant DivePlannerPointsModel::data(const QModelIndex &index, int role) const | ||||||
| 		switch (index.column()) { | 		switch (index.column()) { | ||||||
| 		case REMOVE: | 		case REMOVE: | ||||||
| 			if (rowCount() > 1) | 			if (rowCount() > 1) | ||||||
| 				return p.entered ? QIcon(":trash") : QVariant(); | 				return p.entered ? trashIcon() : QVariant(); | ||||||
|  | 		} | ||||||
|  | 	} else if (role == Qt::SizeHintRole) { | ||||||
|  | 		switch (index.column()) { | ||||||
|  | 		case REMOVE: | ||||||
|  | 			if (rowCount() > 1) | ||||||
|  | 				return p.entered ? trashIcon().size() : QVariant(); | ||||||
| 		} | 		} | ||||||
| 	} else if (role == Qt::FontRole) { | 	} else if (role == Qt::FontRole) { | ||||||
| 		if (divepoints.at(index.row()).entered) { | 		if (divepoints.at(index.row()).entered) { | ||||||
|  |  | ||||||
|  | @ -56,16 +56,31 @@ void CleanerTableModel::setHeaderDataStrings(const QStringList &newHeaders) | ||||||
| 	headers = newHeaders; | 	headers = newHeaders; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | static QPixmap *trashIconPixmap; | ||||||
|  | 
 | ||||||
|  | // initialize the trash icon if necessary
 | ||||||
|  | static void initTrashIcon() { | ||||||
|  | 	if (!trashIconPixmap) | ||||||
|  | 		trashIconPixmap = new QPixmap(QIcon(":trash").pixmap(defaultIconMetrics().sz_small)); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | const QPixmap &trashIcon() { | ||||||
|  | 	return *trashIconPixmap; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| CylindersModel::CylindersModel(QObject *parent) : rows(0) | CylindersModel::CylindersModel(QObject *parent) : rows(0) | ||||||
| { | { | ||||||
| 	//	enum {REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE, DEPTH};
 | 	//	enum {REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE, DEPTH};
 | ||||||
| 	setHeaderDataStrings(QStringList() << "" << tr("Type") << tr("Size") << tr("Work press.") << tr("Start press.") << tr("End press.") << trUtf8("O" UTF8_SUBSCRIPT_2 "%") << tr("He%") | 	setHeaderDataStrings(QStringList() << "" << tr("Type") << tr("Size") << tr("Work press.") << tr("Start press.") << tr("End press.") << trUtf8("O" UTF8_SUBSCRIPT_2 "%") << tr("He%") | ||||||
| 					   << tr("Switch at") | 					   << tr("Switch at") | ||||||
| 			     ); | 			     ); | ||||||
|  | 
 | ||||||
|  | 	initTrashIcon(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| CylindersModel *CylindersModel::instance() | CylindersModel *CylindersModel::instance() | ||||||
| { | { | ||||||
|  | 
 | ||||||
| 	static QScopedPointer<CylindersModel> self(new CylindersModel()); | 	static QScopedPointer<CylindersModel> self(new CylindersModel()); | ||||||
| 	return self.data(); | 	return self.data(); | ||||||
| } | } | ||||||
|  | @ -158,7 +173,11 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const | ||||||
| 		break; | 		break; | ||||||
| 	case Qt::DecorationRole: | 	case Qt::DecorationRole: | ||||||
| 		if (index.column() == REMOVE) | 		if (index.column() == REMOVE) | ||||||
| 			ret = QIcon(":trash"); | 			ret = trashIcon(); | ||||||
|  | 		break; | ||||||
|  | 	case Qt::SizeHintRole: | ||||||
|  | 		if (index.column() == REMOVE) | ||||||
|  | 			ret = trashIcon().size(); | ||||||
| 		break; | 		break; | ||||||
| 
 | 
 | ||||||
| 	case Qt::ToolTipRole: | 	case Qt::ToolTipRole: | ||||||
|  | @ -394,6 +413,8 @@ WeightModel::WeightModel(QObject *parent) : CleanerTableModel(parent), rows(0) | ||||||
| { | { | ||||||
| 	//enum Column {REMOVE, TYPE, WEIGHT};
 | 	//enum Column {REMOVE, TYPE, WEIGHT};
 | ||||||
| 	setHeaderDataStrings(QStringList() << tr("") << tr("Type") << tr("Weight")); | 	setHeaderDataStrings(QStringList() << tr("") << tr("Type") << tr("Weight")); | ||||||
|  | 
 | ||||||
|  | 	initTrashIcon(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| weightsystem_t *WeightModel::weightSystemAt(const QModelIndex &index) | weightsystem_t *WeightModel::weightSystemAt(const QModelIndex &index) | ||||||
|  | @ -449,7 +470,11 @@ QVariant WeightModel::data(const QModelIndex &index, int role) const | ||||||
| 		break; | 		break; | ||||||
| 	case Qt::DecorationRole: | 	case Qt::DecorationRole: | ||||||
| 		if (index.column() == REMOVE) | 		if (index.column() == REMOVE) | ||||||
| 			ret = QIcon(":trash"); | 			ret = trashIcon(); | ||||||
|  | 		break; | ||||||
|  | 	case Qt::SizeHintRole: | ||||||
|  | 		if (index.column() == REMOVE) | ||||||
|  | 			ret = trashIcon().size(); | ||||||
| 		break; | 		break; | ||||||
| 	case Qt::ToolTipRole: | 	case Qt::ToolTipRole: | ||||||
| 		if (index.column() == REMOVE) | 		if (index.column() == REMOVE) | ||||||
|  | @ -1466,6 +1491,8 @@ DiveComputerModel::DiveComputerModel(QMultiMap<QString, DiveComputerNode> &dcMap | ||||||
| 	setHeaderDataStrings(QStringList() << "" << tr("Model") << tr("Device ID") << tr("Nickname")); | 	setHeaderDataStrings(QStringList() << "" << tr("Model") << tr("Device ID") << tr("Nickname")); | ||||||
| 	dcWorkingMap = dcMap; | 	dcWorkingMap = dcMap; | ||||||
| 	numRows = 0; | 	numRows = 0; | ||||||
|  | 
 | ||||||
|  | 	initTrashIcon(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| QVariant DiveComputerModel::data(const QModelIndex &index, int role) const | QVariant DiveComputerModel::data(const QModelIndex &index, int role) const | ||||||
|  | @ -1491,7 +1518,10 @@ QVariant DiveComputerModel::data(const QModelIndex &index, int role) const | ||||||
| 	if (index.column() == REMOVE) { | 	if (index.column() == REMOVE) { | ||||||
| 		switch (role) { | 		switch (role) { | ||||||
| 		case Qt::DecorationRole: | 		case Qt::DecorationRole: | ||||||
| 			ret = QIcon(":trash"); | 			ret = trashIcon(); | ||||||
|  | 			break; | ||||||
|  | 		case Qt::SizeHintRole: | ||||||
|  | 			ret = trashIcon().size(); | ||||||
| 			break; | 			break; | ||||||
| 		case Qt::ToolTipRole: | 		case Qt::ToolTipRole: | ||||||
| 			ret = tr("Clicking here will remove this dive computer."); | 			ret = tr("Clicking here will remove this dive computer."); | ||||||
|  |  | ||||||
|  | @ -89,6 +89,9 @@ private: | ||||||
| 	QString biggerEntry; | 	QString biggerEntry; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | /* Retrieve the trash icon pixmap, common to most table models */ | ||||||
|  | const QPixmap &trashIcon(); | ||||||
|  | 
 | ||||||
| /* Encapsulation of the Cylinder Model, that presents the
 | /* Encapsulation of the Cylinder Model, that presents the
 | ||||||
|  * Current cylinders that are used on a dive. */ |  * Current cylinders that are used on a dive. */ | ||||||
| class CylindersModel : public CleanerTableModel { | class CylindersModel : public CleanerTableModel { | ||||||
|  |  | ||||||
|  | @ -21,7 +21,7 @@ TableView::TableView(QWidget *parent) : QGroupBox(parent) | ||||||
| 	metrics.icon = &defaultIconMetrics(); | 	metrics.icon = &defaultIconMetrics(); | ||||||
| 
 | 
 | ||||||
| 	metrics.col_width = 7*text_em; | 	metrics.col_width = 7*text_em; | ||||||
| 	metrics.rm_col_width = 3*text_em; | 	metrics.rm_col_width = metrics.icon->sz_small + 2*metrics.icon->spacing; | ||||||
| 	metrics.header_ht = text_ht + 10; // TODO DPI
 | 	metrics.header_ht = text_ht + 10; // TODO DPI
 | ||||||
| 
 | 
 | ||||||
| 	/* There`s mostly a need for a Mac fix here too. */ | 	/* There`s mostly a need for a Mac fix here too. */ | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue