int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget window; window.resize(200,200); //label1 QLabel *label1 = new QLabel(&window); QPixmap pm1(100,100); pm1.fill(QColor(255,0,0)); label1->setPixmap(pm1); label1->setFixedSize(100,100); //label2 QLabel *label2 = new QLabel(&window); QPixmap pm2(100,100); pm2.fill(QColor(0,0,255)); label2->setPixmap(pm2); label2->setFixedSize(100,100); label2->move(0,0); label1->move(0,0); //这时候,label1被label2挡住了。 label1->raise();//将label1从父窗口的栈中提升,这样label1就挡住label2了 window.show(); return app.exec(); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void TestErrorMessage() { PipelineMessage e0; QString a0("Some Class Name"); QString a1("Description"); int eCode = -10; PipelineMessage e1; PipelineMessage e2(a0, a1, eCode); AbstractFilter::Pointer f = AbstractFilter::New(); f->notifyErrorMessage("Some Test", a1, eCode); f->notifyErrorMessage("Another Test", "A description", -10); PipelineMessage pm("Joey's Test", "Testing Warning Message...", -23, PipelineMessage::Warning); PipelineMessage pm1("Joey's Test", "Testing Error Message...", -23, PipelineMessage::Error); PipelineMessage pm2("Joey's Test", "Testing Status Message...", -23, PipelineMessage::StatusMessage); PipelineMessage pm3("Joey's Test", "Testing Status Message...", -23, PipelineMessage::ProgressValue, 23); f->broadcastPipelineMessage(pm); f->broadcastPipelineMessage(pm1); f->broadcastPipelineMessage(pm2); if (true) { return; } }
void PManagerTest::test_get_db_name() { Test::print("test_get_db_name "); PManager pm; bool ret = (pm.get_db_name() == DEFAULT_DATABASE_NAME); PManager pm2("test.sql"); ASSERT (ret && (pm2.get_db_name() == "test.sql")) pm.remove_db(); pm2.remove_db(); }
Model2D createSoccerFieldModel() { Model2D m; geo::Vec2 p1(-4, -2.67); geo::Vec2 p2( 4, 2.67); geo::Vec2 pm1(0, p1.y); geo::Vec2 pm2(0, p2.y); createBoxContour(p1, p2, m.addContour()); createBoxContour(pm1, pm2, m.addContour()); createBoxContour(geo::Vec2(p1.x, -1), geo::Vec2(p1.x + 0.5, 1), m.addContour()); createBoxContour(geo::Vec2(p2.x, -1), geo::Vec2(p2.x - 0.5, 1), m.addContour()); createCircleContour(0.7, m.addContour()); return m; }
void calc_camber(data_type &y, data_type &yp, data_type &ypp, data_type &yppp, const data_type &xi) const { // check to make sure given valid parametric value assert((xi>=0) && (xi<=1)); data_type zero(0), one(1), two(2); // short circuit if no camber if (camber==0) { y=zero; yp=zero; ypp=zero; yppp=zero; return; } data_type p = camber; data_type m = camber_loc; if (xi<=m) { data_type pm2(p/(m*m)); y=pm2*(xi*(two*m-xi)); yp=two*pm2*(m-xi); ypp=-two*pm2; yppp=zero; } else { data_type p1m2(p/(one+m*(m-two))); y=p1m2*(one-two*m+xi*(two*m-xi)); yp=two*p1m2*(m-xi); ypp=-two*p1m2; yppp=zero; } }
void ShapeView::updateShapeList() { clear(); setWordWrap(true); for (QHash<QString, shapeData>::Iterator it = m_Shapes.begin(); it != m_Shapes.end(); ++it) { int w = it.value().width + 4; int h = it.value().height + 4; QImage Ico(w, h, QImage::Format_ARGB32_Premultiplied); Ico.fill(0); ScPainter *painter = new ScPainter(&Ico, w, h); painter->setBrush(qRgb(0, 0, 0)); painter->setPen(qRgb(0, 0, 0), 1.0, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); painter->setFillMode(ScPainter::Solid); painter->setStrokeMode(ScPainter::Solid); painter->translate(2.0, 2.0); painter->setupPolygon(&it.value().path); painter->drawPolygon(); painter->end(); delete painter; QPixmap pm; if (w >= h) pm = QPixmap::fromImage(Ico.scaledToWidth(48, Qt::SmoothTransformation)); else pm = QPixmap::fromImage(Ico.scaledToHeight(48, Qt::SmoothTransformation)); QPixmap pm2(48, 48); pm2.fill(palette().color(QPalette::Base)); QPainter p; p.begin(&pm2); p.drawPixmap(24 - pm.width() / 2, 24 - pm.height() / 2, pm); p.end(); QListWidgetItem *item = new QListWidgetItem(pm2, it.value().name, this); item->setData(Qt::UserRole, it.key()); item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled); } }
int main(int argc, const char **argv) { fprintf(stderr, "%s %s\n", __DATE__, __TIME__); bool sane = 1; #define LARGE_MAT #ifdef LARGE_MAT #ifdef BSIM int A = 64; int B = 256; #else int A = 256; int B = 2048; #endif if (argc > 1) { B = strtoul(argv[1], 0, 0); A = 2*B; } srand(A*B); cv::Mat m1(A,B,CV_32F); cv::Mat m2(B,A,CV_32F); for(int a = 0; a < A; a++){ for(int b = 0; b < B; b++){ float v = (float)(rand() % 10); m2.at<float>(b,a) = (A*B)+v; m1.at<float>(a,b) = v; } } #else cv::Mat m1 = (cv::Mat_<float>(4,8) << 11,12,13,14,15,16,17,18, 21,22,23,24,25,26,27,28, 31,32,33,34,35,36,37,38, 41,42,43,44,45,46,47,48 ); cv::Mat m2 = (cv::Mat_<float>(8,4) << 51,62,53,54, 55,56,57,58, 61,62,63,64, 65,66,67,68, 71,72,73,74, 75,76,77,78, 81,82,83,84, 85,86,87,88 ); #endif #ifndef CUDA_PERF_TEST #ifdef MATRIX_NT mmdevice = new MmRequestNTProxy(IfcNames_MmRequestNTS2H); #else #ifdef MATRIX_TN mmdevice = new MmRequestTNProxy(IfcNames_MmRequestTNS2H); #endif #endif MmIndication *mmdeviceIndication = new MmIndication(IfcNames_MmIndicationH2S); //TimerRequestProxy *timerdevice = new TimerRequestProxy(IfcNames_TimerRequestPortalS2H); TimerIndication timerdeviceIndication(IfcNames_TimerIndicationH2S); DmaManager *dma = platformInit(); if(sem_init(&mul_sem, 1, 0)){ fprintf(stderr, "failed to init mul_sem\n"); return -1; } long req_freq = 100000000; long freq = 0; setClockFrequency(0, req_freq, &freq); fprintf(stderr, "Requested FCLK[0]=%ld actually %ld\n", req_freq, freq); matAllocator = new PortalMatAllocator(dma); FILE *octave_file = fopen("foo.m", "w"); fprintf(stderr, "OpenCV matmul\n"); portalTimerStart(0); cv::Mat m3 = m1 * m2; //uint64_t opencv_hw_cycles = portalTimerLap(0); PortalMat tm3; fprintf(stderr, "Naive matmul\n"); portalTimerStart(0); tm3.naive_mul(m1,m2, octave_file); //uint64_t naive_hw_cycles = portalTimerLap(0); if (1) { fprintf(stderr, "DumpMat\n"); dumpMatOctave<float>("m1", "%10.5f", m1, octave_file); dumpMatOctave<float>("m2", "%10.5f", m2, octave_file); dumpMatOctave<float>("m3", "%10.5f", m3, octave_file); dumpMatOctave<float>("tm3", "%10.5f", tm3, octave_file); fclose(octave_file); sane = tm3.compare(m3, 0, 0, 0.0001, 0, false); fprintf(stderr, "sane=%d\n", sane); fflush(stdout); } #ifdef MATRIX_TN fprintf(stderr, "pm1t\n"); PortalMat pm1t(m1.t()); fprintf(stderr, "pm2\n"); PortalMat pm2(m2); pm1t.reference(); pm2.reference(); #else #ifdef MATRIX_NT fprintf(stderr, "pm1\n"); PortalMat pm1(m1); fprintf(stderr, "pm2t\n"); PortalMat pm2t(m2.t()); pm1.reference(); pm2t.reference(); #endif #endif PortalMat pm3; pm3.create(m1.rows, m2.cols, CV_32F); pm3.reference(); // we invoke .reference on the matrices in advance // in order to avoid counting the elapsed time for // performance analysis. This is not strictly necessary // as all the portalmat methods make sure a valid // reference is available before invoking the hardware pthread_t dbgtid; fprintf(stderr, "creating debug thread\n"); if(pthread_create(&dbgtid, NULL, dbgThread, NULL)){ fprintf(stderr, "error creating debug thread\n"); exit(1); } fprintf(stderr, "HW matmul\n"); portalTimerStart(0); #ifdef MATRIX_TN pm3.multf(pm1t, pm2, mmdeviceIndication); #else #ifdef MATRIX_NT pm3.multf(pm1, pm2t, mmdeviceIndication); #endif #endif #if 0 //uint64_t hw_cycles = portalTimerLap(0); uint64_t read_beats = hostMemServerIndication.getMemoryTraffic(ChannelType_Read); uint64_t write_beats = hostMemServerIndication.getMemoryTraffic(ChannelType_Write); float read_util = (float)read_beats/(float)mmdeviceIndication->ccnt; float write_util = (float)write_beats/(float)mmdeviceIndication->ccnt; float read_bw = read_util * N_VALUE * 4 * (float)freq / 1.0e9; float write_bw = write_util * N_VALUE * 4 * (float)freq / 1.0e9; float macs = m1.rows * m2.rows * m2.cols; fprintf(stderr, "Bus frequency %f MHz\n", (float)freq / 1.0e6); fprintf(stderr, "memory read beats %f utilization %f (beats/cycle), bandwidth %f (GB/s)\n", (float)read_beats, read_util, read_bw); fprintf(stderr, "memory write beats %f utilization %f (beats/cycle), bandwidth %f (GB/s)\n", (float)write_beats, write_util, write_bw); fprintf(stderr, "Throughput %f macs/cycle %f GFLOP/s\n", (float)macs / (float)mmdeviceIndication->ccnt, 2.0 * (float)macs / (float)mmdeviceIndication->ccnt * freq / 1.0e9); fprintf(stderr, "Time %f cycles, opencv matmul %f cycles (speedup %f), naive matmul %f cycles (speedup %f)\n", (float)mmdeviceIndication->ccnt, (float)opencv_hw_cycles, (float)opencv_hw_cycles/(float)mmdeviceIndication->ccnt, (float)naive_hw_cycles, (float)naive_hw_cycles/(float)mmdeviceIndication->ccnt); #endif if (0) { dumpMat<float>("pm3", "%5.1f", pm3); dumpMat<float>(" m3", "%5.1f", m3); } bool eq = pm3.compare(m3); #else // CUDA_PERF_TEST cv::Mat cm3(m1.rows,m2.cols, CV_32F); cuda_mm(m1, m2, cm3); cv::Mat m3 = m1 * m2; bool eq = compare(m3, cm3, 0.01); #endif // CUDA_PERF_TEST fprintf(stderr, "XXXXXXXXXXXXXXXXXXXXXXXXXX eq=%d\n", eq); return(!(eq&&sane)); }
EtaKeyboard::EtaKeyboard(QWidget *parent) : QMainWindow(parent) { setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowDoesNotAcceptFocus | Qt::X11BypassWindowManagerHint); QDesktopWidget dw; screenWidth = dw.screenGeometry(dw.primaryScreen()).width(); screenHeight = dw.screenGeometry(dw.primaryScreen()).height(); key_height = screenHeight / 16; key_width = screenWidth / 26; dock_height = screenHeight / 30; m_width = 13*key_width; m_height = key_height*4+dock_height; configpath = QDir::homePath() + "/.config/etak/config.ini"; color = "gray"; Settings::setLanguage("trq"); Settings::setAutoShowBool(true); QFileInfo checkConfig(configpath); if (checkConfig.exists() && checkConfig.isFile()) { preferences = new QSettings(configpath,QSettings::IniFormat); preferences->beginGroup("etak"); Settings::setLanguage(preferences->value("Language").toString()); color= preferences->value("Color").toString(); Settings::setAutoShowBool(preferences->value("AutoShow").toBool()); preferences->endGroup(); } Settings::setColors(color); // 'blue' or 'gray' Helpers::langChange(Settings::getLanguage()); // intialization of X keyboard layout as trq setStyleSheet("background-color: "+Settings::getBackgroundColor()+";"); setGeometry(screenWidth/2+m_width,0,m_width,0); out = LabelInstance::Instance(); // Output text right up to keyboard out->setParent(this); out->setGeometry(0,0,m_width,dock_height); out->setStyleSheet("QLabel{color: white; qproperty-alignment: AlignCenter;}"); QFont f; f.setPointSize(key_height / 5); out->setFont(f); settingsRectangle = new QDialog(this,Qt::X11BypassWindowManagerHint); settingsRectangle->setStyleSheet("background-color: "+Settings::getBackgroundColor()+";"); settingsRectangle->hide(); toggleAuto = new QPushButton(settingsRectangle); toggleAuto->setGeometry(0,0,key_width*2,dock_height); toggleAuto->setCheckable(true); toggleAuto->setChecked(Settings::getAutoShowBool()); if(Settings::getAutoShowBool()) { toggleAuto->setText(QString::fromUtf8("Otomatik çıkma : Kapat")); } else { toggleAuto->setText(QString::fromUtf8("Otomatik çıkma : Aç")); } toggleAuto->setStyleSheet(Settings::getStyleSheet()+Settings::getStyleSheetExtra()); QFont g; g.setPointSize(key_height / 9); toggleAuto->setFont(g); connect(toggleAuto,SIGNAL(clicked()),this,SLOT(toggleAutoShow())); passwordButton = new QPushButton(this); passwordButton->setGeometry(1,1,dock_height,dock_height); passwordButton->setStyleSheet(Settings::getStyleSheet()+Settings::getStyleSheetExtra()); passwordButton->setCheckable(true); passwordButton->setChecked(false); passwordButton->setText("P"); g.setBold(true); g.setPointSize(key_height/4); passwordButton->setFont(g); QRegion *region = new QRegion(*(new QRect(passwordButton->x()+2,passwordButton->y()+2,dock_height-6,dock_height-6)),QRegion::Ellipse); passwordButton->setMask(*region); connect(passwordButton,SIGNAL(clicked()),this,SLOT(togglePassword())); QHash<int, QList<unsigned int> > hash; QList<unsigned int> listtmp; for ( int i = 24 ; i < 36 ; ++i) { listtmp.append(i); } hash.insert(1,listtmp); listtmp.clear(); for ( int j = 38 ; j < 49 ; ++j) { listtmp.append(j); } hash.insert(2,listtmp); listtmp.clear(); for ( int k = 52 ; k < 61 ; ++k) { listtmp.append(k); } hash.insert(3,listtmp); listtmp.clear(); Key *tmp; int posrow = key_width; int posy = dock_height; int posx; AlphaKey *tmp2; QString tmpLanguageLayout =""; if (Settings::getLanguage() == "trq") { tmpLanguageLayout = "TRQ"; } else if (Settings::getLanguage() == "trf") { tmpLanguageLayout = "TRF"; } else if (Settings::getLanguage() == "arabic") { tmpLanguageLayout = QString::fromUtf8("العربئة"); } lang = new SpecialKey(settingsRectangle,0,dock_height,key_width,key_height,tmpLanguageLayout); connect(lang,SIGNAL(clicked()),this,SLOT(changeLanguage())); tmp2 = new AlphaKey(this,0,dock_height,key_width,key_height,9,"Esc"); //Escape alpha_keys.append(tmp2); change = new SpecialKey(this,0,key_height+dock_height,key_width*3/2,key_height,"?123+"); connect(change,SIGNAL(clicked()),this,SLOT(toggleAlterns())); leftshift = new AlphaKey(this,0,key_height*2+dock_height,key_width*2,key_height,50,QString::fromUtf8("↑")); //caps alpha_keys.append(leftshift); connect(leftshift,SIGNAL(clicked()),this,SLOT(toggleCaps())); for (int y = 1 ; y<=3 ; ++y) { posx=posrow; for (int x =0; x < hash[y].length(); ++x) { if (y==2 && x==10) { tmp = new Key(this,posx,posy,key_width*3/2,key_height,hash[y].at(x)); } else { tmp = new Key(this,posx,posy,key_width,key_height,hash[y].at(x)); } keys.append(tmp); posx += key_width; } posy += key_height; posrow += key_width / 2; } tmp2 = new AlphaKey(this, posx, posy - key_height, key_width * 2, key_height, 22, QString::fromUtf8("⌫")); //backspace alpha_keys.append(tmp2); settingsButton = new QPushButton(this); settingsButton->setGeometry(0,posy,key_width,key_height); settingsButton->setStyleSheet(Settings::getStyleSheet()); QPixmap pm(":/icons/gear.png"); settingsButton->setIcon(QIcon(pm)); settingsButton->setIconSize(QSize(settingsButton->width()*2/3,settingsButton->height()*2/3)); connect(settingsButton,SIGNAL(clicked()),this,SLOT(toggleSettings())); hideButton = new QPushButton(this); hideButton->setGeometry(m_width-dock_height-1,1,dock_height,dock_height); QPixmap pm2(":/icons/window-close.png"); hideButton->setIcon(QIcon(pm2)); hideButton->setIconSize(QSize(hideButton->width(),hideButton->height())); connect(hideButton,SIGNAL(clicked()),this,SLOT(animationToggle())); colorButton = new QPushButton(settingsRectangle); colorButton->setGeometry(key_width,dock_height,key_width,key_height); colorButton->setStyleSheet(Settings::getStyleSheet()); connect(colorButton,SIGNAL(clicked()),this,SLOT(toggleColor())); tmp = new Key(this,key_width,posy,key_width,key_height,20); //asterix bottom_keys.append(tmp); tmp = new Key(this,key_width*2,posy,key_width*13/2,key_height,65); // space bottom_keys.append(tmp); tmp = new Key(this,key_width*17/2,posy,key_width,key_height,51); // comma bottom_keys.append(tmp); tmp = new Key(this,key_width*19/2,posy,key_width,key_height,61); // dot bottom_keys.append(tmp); tmp2 = new AlphaKey(this,key_width*21/2,posy,key_width*5/2,key_height,36,QString::fromUtf8("↵")); // enter alpha_keys.append(tmp2); server = new EtaLocalServer(this); Q_CHECK_PTR(server); const QString fullServerName = QString(QDir::homePath()+"/"+SERVER_NAME); QFile file(fullServerName); if (file.exists()) { file.remove(); } if (server->listen(QDir::homePath()+"/"+SERVER_NAME)) { //qDebug() << "Listenning"; } else { //qDebug() << "Failed to listen"; } connect(server, SIGNAL(newCommand(char*)), this, SLOT(onNewCommand(char*))); anime = new QPropertyAnimation(this, "geometry"); tog = false; QList<QString> alternatives; alternatives.append("1"); alternatives.append("2"); alternatives.append("3"); alternatives.append("4"); alternatives.append("5"); alternatives.append("6"); alternatives.append("7"); alternatives.append("8"); alternatives.append("9"); alternatives.append("0"); alternatives.append("braceleft"); alternatives.append("braceright"); alternatives.append("at"); alternatives.append("numbersign"); alternatives.append("dollar"); alternatives.append("percent"); alternatives.append("ampersand"); alternatives.append("parenleft"); alternatives.append("parenright"); alternatives.append("minus"); alternatives.append("less"); alternatives.append("greater"); alternatives.append("exclam"); alternatives.append("semicolon"); alternatives.append("colon"); alternatives.append("apostrophe"); alternatives.append("quotedbl"); alternatives.append("question"); alternatives.append("slash"); alternatives.append("plus"); alternatives.append("equal"); alternatives.append("underscore"); for (int cnt = 0; cnt < keys.size(); ++cnt) { keys.at(cnt)->setAlternString(alternatives.at(cnt)); } }