void QtCalculator::display_selected(){ if(calc_display->Button() == LeftButton){ if(calc_display->isLit()){ QClipboard *cb = QApplication::clipboard(); cb->setText(calc_display->text()); selection_timer->start(100); } else{ selection_timer->stop(); } invertColors(); } else{ QClipboard *cb = QApplication::clipboard(); CALCAMNT result; result = (CALCAMNT) cb->text().toDouble(); // printf("%Lg\n",result); last_input = PASTE; DISPLAY_AMOUNT = result; UpdateDisplay(); } }
ImageViewer::ImageViewer (const KUrl &url, const QString &capText, QWidget *parent) : KDialog( parent ), m_ImageUrl(url), fileIsImage(false), downloadJob(0) { init(url.fileName(), capText); // Add save button setButtons( KDialog::User2 | KDialog::User1 | KDialog::Close ); KGuiItem saveButton( i18n("Save"), "document-save", i18n("Save the image to disk") ); setButtonGuiItem( KDialog::User1, saveButton ); // FIXME: Add more options, and do this more nicely KGuiItem invertButton( i18n("Invert colors"), "", i18n("Reverse colors of the image. This is useful to enhance contrast at times. This affects only the display and not the saving.") ); setButtonGuiItem( KDialog::User2, invertButton ); connect( this, SIGNAL( user1Clicked() ), this, SLOT ( saveFileToDisc() ) ); connect( this, SIGNAL( user2Clicked() ), this, SLOT ( invertColors() ) ); // check URL if (!m_ImageUrl.isValid()) kDebug() << "URL is malformed: " << m_ImageUrl; // FIXME: check the logic with temporary files. Races are possible { KTemporaryFile tempfile; tempfile.open(); file.setFileName( tempfile.fileName() ); }// we just need the name and delete the tempfile from disc; if we don't do it, a dialog will be show loadImageFromURL(); }
void QtCalculator::selection_timed_out(){ // printf("selection timed out\n"); selection_timer->stop(); calc_display->setLit(FALSE); invertColors(); }
void ImageViewer::init(QString caption, QString capText) { setAttribute( Qt::WA_DeleteOnClose, true ); setModal( false ); setWindowTitle( i18n( "KStars image viewer: %1", caption ) ); // Create widget QFrame* page = new QFrame( this ); //setMainWidget( page ); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(page); setLayout(mainLayout); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close); mainLayout->addWidget(buttonBox); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); QPushButton *invertB = new QPushButton(i18n("Invert colors")); invertB->setToolTip(i18n("Reverse colors of the image. This is useful to enhance contrast at times. This affects only the display and not the saving.")); QPushButton *saveB = new QPushButton(QIcon::fromTheme("document-save"), i18n("Save")); saveB->setToolTip(i18n("Save the image to disk")); buttonBox->addButton(invertB, QDialogButtonBox::ActionRole); buttonBox->addButton(saveB, QDialogButtonBox::ActionRole); connect(invertB, SIGNAL(clicked()), this, SLOT(invertColors())); connect(saveB, SIGNAL(clicked()), this, SLOT(saveFileToDisc())); m_View = new ImageLabel( page ); m_View->setAutoFillBackground( true ); m_Caption = new QLabel( page ); m_Caption->setAutoFillBackground( true ); m_Caption->setFrameShape( QFrame::StyledPanel ); m_Caption->setText( capText ); // Add layout QVBoxLayout* vlay = new QVBoxLayout( page ); vlay->setSpacing( 0 ); vlay->setMargin( 0 ); vlay->addWidget( m_View ); vlay->addWidget( m_Caption ); //Reverse colors QPalette p = palette(); p.setColor( QPalette::Window, palette().color( QPalette::WindowText ) ); p.setColor( QPalette::WindowText, palette().color( QPalette::Window ) ); m_Caption->setPalette( p ); m_View->setPalette( p ); //If the caption is wider than the image, try to shrink the font a bit QFont capFont = m_Caption->font(); capFont.setPointSize( capFont.pointSize() - 2 ); m_Caption->setFont( capFont ); }
void ImageViewer::init(QString caption, QString capText) { setAttribute( Qt::WA_DeleteOnClose, true ); setModal( false ); setCaption( i18n( "KStars image viewer" ) + QString( " : " ) + caption ); setButtons( KDialog::Close | KDialog::User1); // FIXME: Add more options, and do this more nicely KGuiItem invertButton( i18n("Invert colors"), "", i18n("Reverse colors of the image. This is useful to enhance contrast at times. This affects only the display and not the saving.") ); setButtonGuiItem( KDialog::User1, invertButton ); connect( this, SIGNAL( user1Clicked() ), this, SLOT ( invertColors() ) ); // Create widget QFrame* page = new QFrame( this ); setMainWidget( page ); m_View = new ImageLabel( page ); m_View->setAutoFillBackground( true ); m_Caption = new QLabel( page ); m_Caption->setAutoFillBackground( true ); m_Caption->setFrameShape( QFrame::StyledPanel ); m_Caption->setText( capText ); // Add layout QVBoxLayout* vlay = new QVBoxLayout( page ); vlay->setSpacing( 0 ); vlay->setMargin( 0 ); vlay->addWidget( m_View ); vlay->addWidget( m_Caption ); //Reverse colors QPalette p = palette(); p.setColor( QPalette::Window, palette().color( QPalette::WindowText ) ); p.setColor( QPalette::WindowText, palette().color( QPalette::Window ) ); m_Caption->setPalette( p ); m_View->setPalette( p ); //If the caption is wider than the image, try to shrink the font a bit QFont capFont = m_Caption->font(); capFont.setPointSize( capFont.pointSize() - 2 ); m_Caption->setFont( capFont ); }
int main (int argc, const char* const argv[]) { char garbage[2]; int command; double sigma; if (4 > argc || 5 < argc) { fprintf (stderr, "syntax: %s <input file> <output file> <command #> ...\n", argv[0]); return 2; } if (1 != sscanf (argv[3], "%d%1s", &command, garbage) || 1 > command || 3 < command) { fprintf (stderr, "Command must be from 1 to 3.\n"); fprintf (stderr, " 1 -- gaussian filter <sigma>\n"); fprintf (stderr, " 2 -- greyscale\n"); fprintf (stderr, " 3 -- invert colors\n"); return 2; } if (1 == command && (5 != argc || 1 != sscanf (argv[4], "%lf%1s", &sigma, garbage) || 0 >= sigma || 100 <= sigma)) { fprintf (stderr, "Sigma must be greater than 0 and less than 100.\n"); return 2; } Image* inputImage = decode (argv[1]); printf ("Width: %d, height: %d\n", inputImage->width, inputImage->height); Image* outputImage = generateOutput (inputImage); int height = inputImage->height; int width = inputImage->width; uint8_t* inRed = inputImage->redChannel; uint8_t* inBlue = inputImage->blueChannel; uint8_t* inGreen = inputImage->greenChannel; uint8_t* inAlpha = inputImage->alphaChannel; uint8_t* outRed = outputImage->redChannel; uint8_t* outBlue = outputImage->blueChannel; uint8_t* outGreen = outputImage->greenChannel; uint8_t* outAlpha = outputImage->alphaChannel; switch (command) { case 1: { int radius = ceil (3 * sigma); int fSize = 1 + 2 * radius; double* gauss = malloc (sizeof (gauss[0]) * fSize * fSize); gaussianFilter (gauss, sigma); convolveImage (width, height, inRed, inGreen, inBlue, inAlpha, radius, gauss, outRed, outGreen, outBlue, outAlpha); encode (argv[2], outputImage); break; } case 2: greyscale (width, height, inRed, inGreen, inBlue, inAlpha, gMonoMult, outRed, outGreen, outBlue, outAlpha); encode (argv[2], outputImage); break; case 3: invertColors (width, height, inRed, inGreen, inBlue, inAlpha, outRed, outGreen, outBlue, outAlpha); encode (argv[2], outputImage); break; } freeImage (inputImage); freeImage (outputImage); return 0; }