Skip to content

Commit

Permalink
Simplified the Panose widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Marchand committed Jan 10, 2011
1 parent 539af18 commit 351285a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 50 deletions.
4 changes: 4 additions & 0 deletions src/panosewidget.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <QSettings> #include <QSettings>
#include <QIcon> #include <QIcon>
#include <QColor> #include <QColor>
#include <QPalette>




PanoseWidget::PanoseWidget(QWidget *parent) : PanoseWidget::PanoseWidget(QWidget *parent) :
Expand All @@ -40,6 +41,9 @@ PanoseWidget::PanoseWidget(QWidget *parent) :
m_filter.clear(); m_filter.clear();
m_filterKey = 0; m_filterKey = 0;


QPalette palette(m_ui->pTree->palette());
palette.setBrush(QPalette::Base, Qt::transparent);
m_ui->pTree->setPalette(palette);


const QMap< FontStrings::PanoseKey, QMap<int, QString> >& p(FontStrings::Panose()); const QMap< FontStrings::PanoseKey, QMap<int, QString> >& p(FontStrings::Panose());
QSettings settings; QSettings settings;
Expand Down
6 changes: 6 additions & 0 deletions src/panosewidget.ui
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
<property name="focusPolicy"> <property name="focusPolicy">
<enum>Qt::NoFocus</enum> <enum>Qt::NoFocus</enum>
</property> </property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="editTriggers"> <property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set> <set>QAbstractItemView::NoEditTriggers</set>
</property> </property>
Expand Down
98 changes: 49 additions & 49 deletions src/tagswidget.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ TagsWidget::TagsWidget ( QWidget * parent )
{ {
setupUi ( this ); setupUi ( this );


tagsListWidget->setContextMenuPolicy ( Qt::CustomContextMenu ); newTagBeingEdited = 0;




connect ( tagsListWidget,SIGNAL ( itemClicked ( QListWidgetItem* ) ),this,SLOT ( slotSwitchCheckState ( QListWidgetItem* ) ) ); connect ( tagsListWidget,SIGNAL ( itemClicked ( QListWidgetItem* ) ),this,SLOT ( slotSwitchCheckState ( QListWidgetItem* ) ) );
connect ( newTagButton,SIGNAL ( clicked ( bool ) ),this,SLOT ( slotNewTag() ) ); connect ( newTagButton,SIGNAL ( clicked ( bool ) ),this,SLOT ( slotNewTag() ) );
// connect ( newTagName, SIGNAL ( editingFinished() ), this, SLOT ( slotNewTag() ) ); connect(removeTagButton, SIGNAL(clicked()), this, SLOT(slotActRemovetag()));
connect ( tagsListWidget,SIGNAL ( customContextMenuRequested ( const QPoint & ) ), this, SLOT ( slotContextMenu ( QPoint ) ) );
connect(tagsListWidget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(slotUpdateCurrentTag(QListWidgetItem*,QListWidgetItem*)));
connect(tagsListWidget, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(slotActEditTag(QListWidgetItem*)));


// connect ( tagsListWidget,SIGNAL ( customContextMenuRequested ( const QPoint & ) ), this, SLOT ( slotContextMenu ( QPoint ) ) );
} }


TagsWidget::~ TagsWidget() TagsWidget::~ TagsWidget()
Expand All @@ -60,20 +65,29 @@ void TagsWidget::slotSwitchCheckState ( QListWidgetItem * item )
slotFinalize(); slotFinalize();
} }


void TagsWidget::slotUpdateCurrentTag(QListWidgetItem *current, QListWidgetItem *previous)
{
if(current)
currentTag = current->text();
}

void TagsWidget::slotNewTag() void TagsWidget::slotNewTag()
{ {
// QString nTag ( newTagName->text() ); if(newTagBeingEdited)
// newTagName->clear(); return;
// bool ok; disconnect(tagsListWidget, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(slotActEditTag(QListWidgetItem*)));
//// nTag = QInputDialog::getText(this,"Fontmatrix",tr("Add new tag"),QLineEdit::Normal, QString() , &ok ); tagsListWidget->setFocus();
// if ( nTag.isEmpty() || FMFontDb::DB()->getTags().contains ( nTag ) ) QString nTag(tr("New Tag"));
// return; newTagBeingEdited = new QListWidgetItem(tagsListWidget);

tagsListWidget->setCurrentItem(newTagBeingEdited);
// FMFontDb::DB()->addTagToDB ( nTag ); newTagBeingEdited->setText(nTag);
// QListWidgetItem *lit = new QListWidgetItem ( nTag ); newTagBeingEdited->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
// lit->setCheckState ( Qt::Checked ); newTagBeingEdited->setCheckState(Qt::Unchecked);
// tagsListWidget->addItem ( lit ); tagsListWidget->scrollToItem(newTagBeingEdited);
// slotFinalize(); FMFontDb::DB()->addTagToDB ( nTag );
currentTag = nTag;
tagsListWidget->openPersistentEditor(newTagBeingEdited);
connect(tagsListWidget, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(slotActEditTag(QListWidgetItem*)));
} }


void TagsWidget::slotFinalize() void TagsWidget::slotFinalize()
Expand Down Expand Up @@ -133,29 +147,9 @@ void TagsWidget::prepare ( QList< FontItem * > fonts )
theTaggedFonts = fonts; theTaggedFonts = fonts;


bool readOnly ( false ); bool readOnly ( false );
// for ( int i ( 0 ); i < theTaggedFonts.count() ; ++i )
// {
// if ( theTaggedFonts[i]->isLocked() )
// {
// readOnly = true;
// break;
// }
// }
tagsListWidget->clear(); tagsListWidget->clear();
// QString tot;
// for ( int i=0;i<theTaggedFonts.count();++i )
// {
// tot.append ( theTaggedFonts[i]->fancyName() + "\n" );
// }
// if ( theTaggedFonts.count() > 1 )
// {
// titleLabel->setText ( theTaggedFonts[0]->family() + " (family)" );
// }
// else
// {
// titleLabel->setText ( theTaggedFonts[0]->fancyName() );
// }
// titleLabel->setToolTip ( tot );
QStringList tagsList ( FMFontDb::DB()->getTags() ); QStringList tagsList ( FMFontDb::DB()->getTags() );


QString sysTag(typotek::getInstance()->getSysTagName()); QString sysTag(typotek::getInstance()->getSysTagName());
Expand All @@ -178,6 +172,7 @@ void TagsWidget::prepare ( QList< FontItem * > fonts )


{ {
lit = new QListWidgetItem ( cur_tag ); lit = new QListWidgetItem ( cur_tag );
lit->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
lit->setCheckState ( Qt::Unchecked ); lit->setCheckState ( Qt::Unchecked );
int YesState = 0; int YesState = 0;
for ( int i=0;i<theTaggedFonts.count();++i ) for ( int i=0;i<theTaggedFonts.count();++i )
Expand Down Expand Up @@ -262,22 +257,27 @@ void TagsWidget::slotActRemovetag()


} }


void TagsWidget::slotActEditTag() void TagsWidget::slotActEditTag(QListWidgetItem * item )
{ {
// qDebug()<<"TagsWidget::slotActEditTag"; if(!item)
// QString fromT(currentTag); return;
QString message; QString newTag(item->text());
message = tr ( "Please provide a replacement name for\nthe following tag:") + " " + currentTag ; if(newTag.isEmpty())
QString nt = QInputDialog::getText ( typotek::getInstance(),
"Fontmatrix",
message,
QLineEdit::Normal,
currentTag ) ;
if ( ( nt != currentTag ) && ( !nt.isEmpty() ) )
{ {
FMFontDb::DB()->editTag ( currentTag, nt ); item->setText(currentTag);
return;
}
if ( ( newTag != currentTag ) && (!currentTag.isEmpty()))
{
FMFontDb::DB()->editTag ( currentTag, newTag );
prepare(theTaggedFonts); prepare(theTaggedFonts);
} }

if(newTagBeingEdited == item)
{
tagsListWidget->closePersistentEditor(newTagBeingEdited);
newTagBeingEdited = 0;
}


} }


Expand Down
6 changes: 5 additions & 1 deletion src/tagswidget.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class TagsWidget : public QWidget , private Ui::tagsWidget
QList<QAction*> contAction; QList<QAction*> contAction;


QString currentTag; QString currentTag;

QListWidgetItem * newTagBeingEdited;


public: public:
TagsWidget(QWidget * parent); TagsWidget(QWidget * parent);
Expand All @@ -40,10 +42,12 @@ class TagsWidget : public QWidget , private Ui::tagsWidget
void slotSwitchCheckState( QListWidgetItem * item ); void slotSwitchCheckState( QListWidgetItem * item );
void slotNewTag(); void slotNewTag();
void slotFinalize(); void slotFinalize();

void slotUpdateCurrentTag(QListWidgetItem * current, QListWidgetItem * previous);


void slotContextMenu( QPoint pos ); void slotContextMenu( QPoint pos );
void slotActRemovetag(); void slotActRemovetag();
void slotActEditTag(); void slotActEditTag(QListWidgetItem * item );


}; };


Expand Down

0 comments on commit 351285a

Please sign in to comment.