22 #include <QFontMetrics>
25 #include <QGraphicsProxyWidget>
28 #include <KIconLoader>
30 #include <plasma/theme.h>
31 #include <plasma/dataengine.h>
32 #include <plasma/tooltipcontent.h>
33 #include <plasma/tooltipmanager.h>
35 #include <analitza/expression.h>
37 using namespace Plasma;
38 using Analitza::Expression;
40 QColor KAlgebraPlasmoid::correctColor() {
return Theme::defaultTheme()->color(Theme::TextColor);}
41 QColor KAlgebraPlasmoid::errorColor() {
return Qt::red; }
42 int KAlgebraPlasmoid::simplificationSize() {
return Theme::defaultTheme()->font(Theme::DefaultFont).pointSize(); }
45 : PopupApplet(parent, args), m_widget(0), m_layout(0)
47 KGlobal::locale()->insertCatalog(
"kalgebra");
48 setAspectRatioMode(IgnoreAspectRatio);
49 setAssociatedApplication(
"kalgebra");
58 setPopupIcon(
"kalgebra");
65 m_input =
new Plasma::LineEdit(m_widget);
66 m_input->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
67 m_input->setClearButtonShown(
true);
69 m_output =
new Plasma::Label(m_widget);
70 m_output->setMinimumSize(20, 20);
71 m_output->nativeWidget()->setAlignment(Qt::AlignCenter);
72 m_output->setText(i18n(
"Enter some expression."));
80 connect(m_input, SIGNAL(editingFinished()),
this, SLOT(addOperation()));
81 connect(m_input->nativeWidget(), SIGNAL(textChanged(
QString)),
this, SLOT(simplify()));
83 m_input->nativeWidget()->selectAll();
89 void KAlgebraPlasmoid::addOperation()
91 if ( m_input->text().isEmpty() )
95 a.setExpression(Expression(m_input->text(),
false));
103 m_output->setText(result);
105 Plasma::ToolTipContent data;
106 data.setMainText(i18n(
"KAlgebra"));
107 data.setSubText(i18n(
"%1 = %2", m_input->text(), result));
108 data.setImage(KIcon(
"kalgebra").pixmap(IconSize(KIconLoader::Desktop)));
109 Plasma::ToolTipManager::self()->setContent(
this, data);
113 m_output->setText(a.errors().join(
"\n"));
116 plasmoidFont(
true, c,
true);
120 void KAlgebraPlasmoid::plasmoidFont(
bool big,
const QColor& c,
bool bold)
122 QFont f=m_output->nativeWidget()->font();
127 size=(m_output->size().height()*2)/3;
131 int w=m_output->size().width();
133 for(; fm.width(m_output->text()) > w; size--) {
138 size=simplificationSize();
141 QPalette palette = m_output->palette();
142 palette.
setColor(QPalette::WindowText, c);
143 m_output->nativeWidget()->setPalette(palette);
144 m_output->nativeWidget()->setFont(f);
147 void KAlgebraPlasmoid::simplify()
149 Expression e(m_input->text(),
false);
153 if(e.isCorrect() && a.isCorrect()) {
155 m_output->setText(a.expression().toString());
157 plasmoidFont(
false, correctColor(),
true);
162 #include "kalgebraplasma.moc"
void setPointSize(int pointSize)
void setColor(ColorGroup group, ColorRole role, const QColor &color)
void setOrientation(Qt::Orientation orientation)
KAlgebraPlasmoid(QObject *parent, const QVariantList &args)
void setBold(bool enable)
virtual QGraphicsWidget * graphicsWidget()
void addItem(QGraphicsLayoutItem *item)
void setPreferredSize(const QSizeF &size)